Skip to content

Commit

Permalink
Fix some unchecked mallocs.
Browse files Browse the repository at this point in the history
BUG=456599

Change-Id: Id0652c2aff1cb8a5de35350feb8410285b3fef20
Reviewed-on: https://boringssl-review.googlesource.com/3330
Reviewed-by: Adam Langley <[email protected]>
  • Loading branch information
davidben authored and agl committed Feb 9, 2015
1 parent 42ca3a4 commit 1eed2c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crypto/rand/urandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ int RAND_bytes(uint8_t *out, size_t requested) {

if (!buf) {
buf = (struct rand_buffer *)OPENSSL_malloc(BUF_SIZE);
if (!buf) {
abort();
return 0;
}
/* The buffer doesn't contain any random bytes yet
* so we mark it as fully used so that it will be
* filled below. */
Expand Down
6 changes: 6 additions & 0 deletions crypto/x509/by_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
if (!hent)
{
hent = OPENSSL_malloc(sizeof(BY_DIR_HASH));
if (hent == NULL)
{
CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
ok = 0;
goto finish;
}
hent->hash = h;
hent->suffix = k;
if (!sk_BY_DIR_HASH_push(ent->hashes, hent))
Expand Down
2 changes: 2 additions & 0 deletions crypto/x509v3/v3_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
return 0;
objlen = p - value;
objtmp = OPENSSL_malloc(objlen + 1);
if (objtmp == NULL)
return 0;
strncpy(objtmp, value, objlen);
objtmp[objlen] = 0;
gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
Expand Down
5 changes: 3 additions & 2 deletions ssl/ssl_ciph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,9 @@ const char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf,
if (buf == NULL) {
len = 128;
buf = OPENSSL_malloc(len);
if (buf == NULL)
return "OPENSSL_malloc Error";
if (buf == NULL) {
return NULL;
}
} else if (len < 128) {
return "Buffer too small";
}
Expand Down

0 comments on commit 1eed2c0

Please sign in to comment.