Module Name: src Committed By: agc Date: Fri Oct 9 06:02:56 UTC 2009
Modified Files: src/crypto/external/bsd/netpgp/dist/src/lib: misc.c packet-parse.c packet-show.c packet.h Log Message: Add some checks for return value from allocation routines To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/crypto/external/bsd/netpgp/dist/src/lib/misc.c cvs rdiff -u -r1.25 -r1.26 \ src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c cvs rdiff -u -r1.13 -r1.14 \ src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c cvs rdiff -u -r1.15 -r1.16 \ src/crypto/external/bsd/netpgp/dist/src/lib/packet.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/crypto/external/bsd/netpgp/dist/src/lib/misc.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/misc.c:1.22 src/crypto/external/bsd/netpgp/dist/src/lib/misc.c:1.23 --- src/crypto/external/bsd/netpgp/dist/src/lib/misc.c:1.22 Wed Oct 7 16:19:51 2009 +++ src/crypto/external/bsd/netpgp/dist/src/lib/misc.c Fri Oct 9 06:02:55 2009 @@ -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"); Index: src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c:1.25 src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c:1.26 --- src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c:1.25 Wed Oct 7 16:19:51 2009 +++ src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c Fri Oct 9 06:02:55 2009 @@ -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; Index: src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c:1.13 src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c:1.14 --- src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c:1.13 Wed Oct 7 04:18:47 2009 +++ src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c Fri Oct 9 06:02:55 2009 @@ -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; } Index: src/crypto/external/bsd/netpgp/dist/src/lib/packet.h diff -u src/crypto/external/bsd/netpgp/dist/src/lib/packet.h:1.15 src/crypto/external/bsd/netpgp/dist/src/lib/packet.h:1.16 --- src/crypto/external/bsd/netpgp/dist/src/lib/packet.h:1.15 Tue Oct 6 05:54:24 2009 +++ src/crypto/external/bsd/netpgp/dist/src/lib/packet.h Fri Oct 9 06:02:55 2009 @@ -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)