Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib Add some checks for ...
details: https://anonhg.NetBSD.org/src/rev/82278ac06780
branches: trunk
changeset: 748007:82278ac06780
user: agc <agc%NetBSD.org@localhost>
date: Fri Oct 09 06:02:55 2009 +0000
description:
Add some checks for return value from allocation routines
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/misc.c | 11 ++++-
crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c | 35 +++++++++++++++--
crypto/external/bsd/netpgp/dist/src/lib/packet-show.c | 4 +-
crypto/external/bsd/netpgp/dist/src/lib/packet.h | 8 +++-
4 files changed, 48 insertions(+), 10 deletions(-)
diffs (162 lines):
diff -r 51e3b71a8453 -r 82278ac06780 crypto/external/bsd/netpgp/dist/src/lib/misc.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/misc.c Fri Oct 09 00:48:33 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/misc.c Fri Oct 09 06:02:55 2009 +0000
@@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: misc.c,v 1.22 2009/10/07 16:19:51 agc Exp $");
+__RCSID("$NetBSD: misc.c,v 1.23 2009/10/09 06:02:55 agc Exp $");
#endif
#include <sys/types.h>
@@ -817,13 +817,20 @@
void
__ops_memory_pad(__ops_memory_t *mem, size_t length)
{
+ unsigned char *temp;
+
if (mem->allocated < mem->length) {
(void) fprintf(stderr, "__ops_memory_pad: bad alloc in\n");
return;
}
if (mem->allocated < mem->length + length) {
mem->allocated = mem->allocated * 2 + length;
- mem->buf = realloc(mem->buf, mem->allocated);
+ temp = realloc(mem->buf, mem->allocated);
+ if (temp == NULL) {
+ (void) fprintf(stderr, "__ops_memory_pad: bad alloc\n");
+ } else {
+ mem->buf = temp;
+ }
}
if (mem->allocated < mem->length + length) {
(void) fprintf(stderr, "__ops_memory_pad: bad alloc out\n");
diff -r 51e3b71a8453 -r 82278ac06780 crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c Fri Oct 09 00:48:33 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c Fri Oct 09 06:02:55 2009 +0000
@@ -58,7 +58,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: packet-parse.c,v 1.25 2009/10/07 16:19:51 agc Exp $");
+__RCSID("$NetBSD: packet-parse.c,v 1.26 2009/10/09 06:02:55 agc Exp $");
#endif
#ifdef HAVE_OPENSSL_CAST_H
@@ -1699,6 +1699,10 @@
pkt.u.ss_raw.tag = pkt.tag;
pkt.u.ss_raw.length = subregion.length - 1;
pkt.u.ss_raw.raw = calloc(1, pkt.u.ss_raw.length);
+ if (pkt.u.ss_raw.raw == NULL) {
+ (void) fprintf(stderr, "parse_one_sig_subpacket: bad alloc\n");
+ return 0;
+ }
if (!limread(pkt.u.ss_raw.raw, pkt.u.ss_raw.length,
&subregion, stream)) {
return 0;
@@ -2073,6 +2077,10 @@
free(pkt.u.sig.info.v4_hashed);
}
pkt.u.sig.info.v4_hashed = calloc(1, pkt.u.sig.info.v4_hashlen);
+ if (pkt.u.sig.info.v4_hashed == NULL) {
+ (void) fprintf(stderr, "parse_v4_sig: bad alloc\n");
+ return 0;
+ }
if (!stream->readinfo.accumulate) {
/* We must accumulate, else we can't check the signature */
@@ -2232,8 +2240,15 @@
{
__ops_hashtype_t *hash;
- stream->hashes = realloc(stream->hashes,
+ hash = realloc(stream->hashes,
(stream->hashc + 1) * sizeof(*stream->hashes));
+ if (hash == NULL) {
+ (void) fprintf(stderr, "parse_hash_init: bad alloc 0\n");
+ /* just continue and die here */
+ /* XXX - agc - no way to return failure */
+ } else {
+ stream->hashes = hash;
+ }
hash = &stream->hashes[stream->hashc++];
__ops_hash_any(&hash->hash, type);
@@ -2678,6 +2693,10 @@
}
if (pkt.u.seckey.s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED) {
pkt.u.seckey.checkhash = calloc(1, OPS_CHECKHASH_SIZE);
+ if (pkt.u.seckey.checkhash == NULL) {
+ (void) fprintf(stderr, "parse_seckey: bad alloc\n");
+ return 0;
+ }
__ops_hash_sha1(&checkhash);
__ops_reader_push_hash(stream, &checkhash);
} else {
@@ -2934,6 +2953,10 @@
__ops_crypt_any(&stream->decrypt, pkt.u.pk_sesskey.symm_alg);
iv = calloc(1, stream->decrypt.blocksize);
+ if (iv == NULL) {
+ (void) fprintf(stderr, "parse_pk_sesskey: bad alloc\n");
+ return 0;
+ }
stream->decrypt.set_iv(&stream->decrypt, iv);
stream->decrypt.set_crypt_key(&stream->decrypt, pkt.u.pk_sesskey.key);
__ops_encrypt_init(&stream->decrypt);
@@ -3458,8 +3481,12 @@
void
__ops_callback_push(__ops_stream_t *stream, __ops_cbfunc_t *cb, void *arg)
{
- __ops_cbdata_t *cbinfo = calloc(1, sizeof(*cbinfo));
-
+ __ops_cbdata_t *cbinfo;
+
+ if ((cbinfo = calloc(1, sizeof(*cbinfo))) == NULL) {
+ (void) fprintf(stderr, "__ops_callback_push: bad alloc\n");
+ return;
+ }
(void) memcpy(cbinfo, &stream->cbinfo, sizeof(*cbinfo));
cbinfo->io = stream->io;
stream->cbinfo.next = cbinfo;
diff -r 51e3b71a8453 -r 82278ac06780 crypto/external/bsd/netpgp/dist/src/lib/packet-show.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c Fri Oct 09 00:48:33 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c Fri Oct 09 06:02:55 2009 +0000
@@ -60,7 +60,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: packet-show.c,v 1.13 2009/10/07 04:18:47 agc Exp $");
+__RCSID("$NetBSD: packet-show.c,v 1.14 2009/10/09 06:02:55 agc Exp $");
#endif
#include <stdlib.h>
@@ -354,7 +354,7 @@
list->size = newsize;
return 1;
}
- /* xxx - realloc failed. error message? - rachel */
+ (void) fprintf(stderr, "list_resize - bad alloc\n");
return 0;
}
diff -r 51e3b71a8453 -r 82278ac06780 crypto/external/bsd/netpgp/dist/src/lib/packet.h
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet.h Fri Oct 09 00:48:33 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet.h Fri Oct 09 06:02:55 2009 +0000
@@ -1071,9 +1071,13 @@
#define EXPAND_ARRAY(str, arr) do { \
if (str->arr##c == str->arr##vsize) { \
+ void *__newarr; \
str->arr##vsize = (str->arr##vsize * 2) + 10; \
- str->arr##s = realloc(str->arr##s, \
- str->arr##vsize * sizeof(*str->arr##s)); \
+ if ((__newarr = realloc(str->arr##s, \
+ str->arr##vsize * sizeof(*str->arr##s))) == NULL) { \
+ (void) fprintf(stderr, "EXPAND_ARRAY - bad realloc\n"); \
+ } \
+ str->arr##s = __newarr; \
} \
} while(/*CONSTCOND*/0)
Home |
Main Index |
Thread Index |
Old Index