Unchecked malloc fixes

Miscellaneous unchecked malloc fixes. Also fixed some mem leaks on error
paths as I spotted them along the way.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit 918bb86529)

Conflicts:
	crypto/bio/bss_dgram.c
This commit is contained in:
Matt Caswell
2015-03-04 17:49:51 +00:00
parent 9fdbaf3a32
commit d6b4a41d10
21 changed files with 158 additions and 12 deletions

View File

@@ -696,6 +696,8 @@ static int ebcdic_new(BIO *bi)
EBCDIC_OUTBUFF *wbuf;
wbuf = (EBCDIC_OUTBUFF *) OPENSSL_malloc(sizeof(EBCDIC_OUTBUFF) + 1024);
if (!wbuf)
return 0;
wbuf->alloced = 1024;
wbuf->buff[0] = '\0';
@@ -750,9 +752,11 @@ static int ebcdic_write(BIO *b, const char *in, int inl)
num = num + num; /* double the size */
if (num < inl)
num = inl;
OPENSSL_free(wbuf);
wbuf =
(EBCDIC_OUTBUFF *) OPENSSL_malloc(sizeof(EBCDIC_OUTBUFF) + num);
if(!wbuf)
return 0;
OPENSSL_free(b->ptr);
wbuf->alloced = num;
wbuf->buff[0] = '\0';
@@ -3319,6 +3323,10 @@ static int add_session(SSL *ssl, SSL_SESSION *session)
unsigned char *p;
sess = OPENSSL_malloc(sizeof(simple_ssl_session));
if(!sess) {
BIO_printf(bio_err, "Out of memory adding session to external cache\n");
return 0;
}
SSL_SESSION_get_id(session, &sess->idlen);
sess->derlen = i2d_SSL_SESSION(session, NULL);
@@ -3326,6 +3334,16 @@ static int add_session(SSL *ssl, SSL_SESSION *session)
sess->id = BUF_memdup(SSL_SESSION_get_id(session, NULL), sess->idlen);
sess->der = OPENSSL_malloc(sess->derlen);
if(!sess->id || !sess->der) {
BIO_printf(bio_err, "Out of memory adding session to external cache\n");
if(sess->id)
OPENSSL_free(sess->id);
if(sess->der)
OPENSSL_free(sess->der);
OPENSSL_free(sess);
return 0;
}
p = sess->der;
i2d_SSL_SESSION(session, &p);