external/boringssl: Sync to 3ef7697ed30f28367395a5aafb57a12a19906d96.
This includes the following changes:
https://boringssl.googlesource.com/boringssl/+log/3cbdc34619daafb9f8527fb9dd27afc8ee7dcf19..3ef7697ed30f28367395a5aafb57a12a19906d96
This also updates the UPDATING script to create the git commit
automatically.
Test: make checkbuild
Test: cts-tradefed run cts -m CtsLibcoreOkHttpTestCases -a arm64-v8a
Test: cts-tradefed run cts -m CtsLibcoreTestCases -a arm64-v8a
Change-Id: I9e785971e5be19daf29697f010c3ae4e1ca70b04
diff --git a/src/crypto/test/malloc.cc b/src/crypto/test/malloc.cc
index 47ee6da..33f0972 100644
--- a/src/crypto/test/malloc.cc
+++ b/src/crypto/test/malloc.cc
@@ -26,9 +26,13 @@
// This file isn't built on ARM or Aarch64 because we link statically in those
// builds and trying to override malloc in a static link doesn't work. It also
-// requires glibc.
+// requires glibc. It's also disabled on ASan builds as this interferes with
+// ASan's malloc interceptor.
+//
+// TODO(davidben): See if this and ASan's and MSan's interceptors can be made to
+// coexist.
#if defined(__linux__) && defined(OPENSSL_GLIBC) && !defined(OPENSSL_ARM) && \
- !defined(OPENSSL_AARCH64)
+ !defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN)
#include <errno.h>
#include <signal.h>
@@ -40,38 +44,23 @@
#include <new>
-/* This file defines overrides for the standard allocation functions that allow
- * a given allocation to be made to fail for testing. If the program is run
- * with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will
- * return NULL. If MALLOC_BREAK_ON_FAIL is also defined then the allocation
- * will signal SIGTRAP rather than return NULL.
- *
- * This code is not thread safe. */
+// This file defines overrides for the standard allocation functions that allow
+// a given allocation to be made to fail for testing. If the program is run
+// with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will
+// return NULL. If MALLOC_BREAK_ON_FAIL is also defined then the allocation
+// will signal SIGTRAP rather than return NULL.
+//
+// This code is not thread safe.
static uint64_t current_malloc_count = 0;
static uint64_t malloc_number_to_fail = 0;
-static char failure_enabled = 0, break_on_fail = 0;
-static int in_call = 0;
+static bool failure_enabled = false, break_on_fail = false, in_call = false;
extern "C" {
-
-#if defined(OPENSSL_ASAN)
-#define REAL_MALLOC __interceptor_malloc
-#define REAL_CALLOC __interceptor_calloc
-#define REAL_REALLOC __interceptor_realloc
-#define REAL_FREE __interceptor_free
-#else
-#define REAL_MALLOC __libc_malloc
-#define REAL_CALLOC __libc_calloc
-#define REAL_REALLOC __libc_realloc
-#define REAL_FREE __libc_free
-#endif
-
-/* These are other names for the standard allocation functions. */
-extern void *REAL_MALLOC(size_t size);
-extern void *REAL_CALLOC(size_t num_elems, size_t size);
-extern void *REAL_REALLOC(void *ptr, size_t size);
-extern void REAL_FREE(void *ptr);
+// These are other names for the standard allocation functions.
+extern void *__libc_malloc(size_t size);
+extern void *__libc_calloc(size_t num_elems, size_t size);
+extern void *__libc_realloc(void *ptr, size_t size);
}
static void exit_handler(void) {
@@ -85,16 +74,15 @@
return;
}
-/* should_fail_allocation returns true if the current allocation should fail. */
-static int should_fail_allocation() {
- static int init = 0;
- char should_fail;
+// should_fail_allocation returns true if the current allocation should fail.
+static bool should_fail_allocation() {
+ static bool init = false;
if (in_call) {
- return 0;
+ return false;
}
- in_call = 1;
+ in_call = true;
if (!init) {
const char *env = getenv("MALLOC_NUMBER_TO_FAIL");
@@ -102,22 +90,22 @@
char *endptr;
malloc_number_to_fail = strtoull(env, &endptr, 10);
if (*endptr == 0) {
- failure_enabled = 1;
+ failure_enabled = true;
atexit(exit_handler);
std::set_new_handler(cpp_new_handler);
}
}
break_on_fail = (NULL != getenv("MALLOC_BREAK_ON_FAIL"));
- init = 1;
+ init = true;
}
- in_call = 0;
+ in_call = false;
if (!failure_enabled) {
- return 0;
+ return false;
}
- should_fail = (current_malloc_count == malloc_number_to_fail);
+ bool should_fail = (current_malloc_count == malloc_number_to_fail);
current_malloc_count++;
if (should_fail && break_on_fail) {
@@ -134,7 +122,7 @@
return NULL;
}
- return REAL_MALLOC(size);
+ return __libc_malloc(size);
}
void *calloc(size_t num_elems, size_t size) {
@@ -143,7 +131,7 @@
return NULL;
}
- return REAL_CALLOC(num_elems, size);
+ return __libc_calloc(num_elems, size);
}
void *realloc(void *ptr, size_t size) {
@@ -152,11 +140,7 @@
return NULL;
}
- return REAL_REALLOC(ptr, size);
-}
-
-void free(void *ptr) {
- REAL_FREE(ptr);
+ return __libc_realloc(ptr, size);
}
} // extern "C"