Add and use OPENSSL_zalloc

There are many places (nearly 50) where we malloc and then memset.
Add an OPENSSL_zalloc routine to encapsulate that.
(Missed one conversion; thanks Richard)
Also fixes GH328

Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
Rich Salz
2015-08-25 13:25:58 -04:00
committed by Rich Salz
parent 66e87a9f09
commit b51bce9420
45 changed files with 82 additions and 168 deletions

View File

@@ -440,10 +440,8 @@ int test_builtin(BIO *out)
goto builtin_err;
}
buf_len = 2 * bn_len;
if ((raw_buf = OPENSSL_malloc(buf_len)) == NULL)
if ((raw_buf = OPENSSL_zalloc(buf_len)) == NULL)
goto builtin_err;
/* Pad the bignums with leading zeroes. */
memset(raw_buf, 0, buf_len);
BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len);
BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len);

View File

@@ -2116,14 +2116,11 @@ int doit(SSL *s_ssl, SSL *c_ssl, long count)
bufsiz = count > 40 * 1024 ? 40 * 1024 : count;
if ((cbuf = OPENSSL_malloc(bufsiz)) == NULL)
if ((cbuf = OPENSSL_zalloc(bufsiz)) == NULL)
goto err;
if ((sbuf = OPENSSL_malloc(bufsiz)) == NULL)
if ((sbuf = OPENSSL_zalloc(bufsiz)) == NULL)
goto err;
memset(cbuf, 0, bufsiz);
memset(sbuf, 0, bufsiz);
c_to_s = BIO_new(BIO_s_mem());
s_to_c = BIO_new(BIO_s_mem());
if ((s_to_c == NULL) || (c_to_s == NULL)) {