Add some checks for return value from allocation routines
This commit is contained in:
parent
5054c08e3a
commit
0aa9bcca65
|
@ -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 @@ __ops_memory_init(__ops_memory_t *mem, size_t needed)
|
|||
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");
|
||||
|
|
|
@ -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 @@ parse_one_sig_subpacket(__ops_sig_t *sig,
|
|||
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 @@ parse_v4_sig(__ops_region_t *region, __ops_stream_t *stream)
|
|||
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 @@ parse_hash_init(__ops_stream_t *stream, __ops_hash_alg_t type,
|
|||
{
|
||||
__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 @@ parse_seckey(__ops_region_t *region, __ops_stream_t *stream)
|
|||
}
|
||||
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 @@ parse_pk_sesskey(__ops_region_t *region,
|
|||
|
||||
__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 @@ __ops_set_callback(__ops_stream_t *stream, __ops_cbfunc_t *cb, void *arg)
|
|||
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;
|
||||
|
|
|
@ -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_resize(__ops_list_t *list)
|
|||
list->size = newsize;
|
||||
return 1;
|
||||
}
|
||||
/* xxx - realloc failed. error message? - rachel */
|
||||
(void) fprintf(stderr, "list_resize - bad alloc\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1071,9 +1071,13 @@ int __ops_print_packet(const __ops_packet_t *);
|
|||
|
||||
#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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue