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>
This commit is contained in:
Adam Langley 2020-02-05 15:23:07 -08:00
parent 7e43e2e8ee
commit 7964a1d676

View File

@ -105,6 +105,10 @@ void sdallocx(void *ptr, size_t size, int flags) {
}
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;