commit | 7964a1d6768650b8d34da23842f3f14851722afc | [log] [tgz] |
---|---|---|
author | Adam Langley <agl@google.com> | Wed Feb 05 15:23:07 2020 -0800 |
committer | Adam Langley <agl@google.com> | Mon Feb 10 17:43:35 2020 +0000 |
tree | 0c150e76b26e1eef1c0be85270b13022fb5878b2 | |
parent | 7e43e2e8eecc9114f829e6d75cc3c04d1af57504 [diff] |
Check for overflow in massive mallocs. Hopefully it never happens, but a malloc of nearly the whole address space should fail cleanly. Change-Id: I82499e3236a1a485f5518b1c048899b1df3e8488 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39864 Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/crypto/mem.c b/crypto/mem.c index 7fc5f98..a864a66 100644 --- a/crypto/mem.c +++ b/crypto/mem.c
@@ -105,6 +105,10 @@ } void *OPENSSL_malloc(size_t size) { + if (size + OPENSSL_MALLOC_PREFIX < size) { + return NULL; + } + void *ptr = malloc(size + OPENSSL_MALLOC_PREFIX); if (ptr == NULL) { return NULL;