Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@chromium.org>2015-06-13 01:08:51 +0300
committerAdam Langley <agl@google.com>2015-06-15 20:53:08 +0300
commit2b2b0f909df7ab69ae51c6a9816d57c78b9ed84f (patch)
treeff4b53a0c4c9050fae1d28cc7b24d7c418fe7701 /crypto/test
parent1c703cb0c1e73d49af6bc837a7442f06a3dbcf08 (diff)
Set errno to ENOMEM when simulating a malloc failure.
Per malloc(3): The UNIX 98 standard requires malloc(), calloc(), and realloc() to set errno to ENOMEM upon failure. Glibc assumes that this is done (and the glibc versions of these routines do this); if you use a private malloc implementation that does not set errno, then certain library routines may fail without having a reason in errno. Notably, thread_test otherwise fails an assertion deep in glibc. Change-Id: Ia2c0ab306987476e7d6570d4bbf04a2641398925 Reviewed-on: https://boringssl-review.googlesource.com/5111 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/malloc.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/crypto/test/malloc.cc b/crypto/test/malloc.cc
index 9ffdf014..31da2c78 100644
--- a/crypto/test/malloc.cc
+++ b/crypto/test/malloc.cc
@@ -34,6 +34,7 @@
#if defined(__linux__) && defined(OPENSSL_GLIBC) && !defined(OPENSSL_ARM) && \
!defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN)
+#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -118,6 +119,7 @@ extern "C" {
void *malloc(size_t size) {
if (should_fail_allocation()) {
+ errno = ENOMEM;
return NULL;
}
@@ -126,6 +128,7 @@ void *malloc(size_t size) {
void *calloc(size_t num_elems, size_t size) {
if (should_fail_allocation()) {
+ errno = ENOMEM;
return NULL;
}
@@ -134,6 +137,7 @@ void *calloc(size_t num_elems, size_t size) {
void *realloc(void *ptr, size_t size) {
if (should_fail_allocation()) {
+ errno = ENOMEM;
return NULL;
}