diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-14 01:00:41 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-14 01:00:41 +0000 |
commit | 5faa9b573141557f36d74f6f5fe9c36dfc2d46e7 (patch) | |
tree | 06954b7cc78e18d94b6c63147ad20eb6181adf63 | |
parent | 7492bd39ae31493616b1223dbd97f6539344b677 (diff) | |
parent | 41914461b6e6085359909902195a095846f67925 (diff) |
Snap for 8451755 from 41914461b6e6085359909902195a095846f67925 to tm-release
Change-Id: Ibad24a5f6226a2e6f91e6951d1b8af0671da796c
-rw-r--r-- | libc/bionic/android_set_abort_message.cpp | 4 | ||||
-rw-r--r-- | libc/bionic/gwp_asan_wrappers.cpp | 15 | ||||
-rw-r--r-- | tests/Android.bp | 1 | ||||
-rw-r--r-- | tests/NOTICE | 28 | ||||
-rw-r--r-- | tests/android_set_abort_message_test.cpp | 43 |
5 files changed, 89 insertions, 2 deletions
diff --git a/libc/bionic/android_set_abort_message.cpp b/libc/bionic/android_set_abort_message.cpp index 2ea12ee54..d5f8cb97f 100644 --- a/libc/bionic/android_set_abort_message.cpp +++ b/libc/bionic/android_set_abort_message.cpp @@ -77,6 +77,10 @@ void android_set_abort_message(const char* msg) { return; } + if (msg == nullptr) { + msg = "(null)"; + } + size_t size = sizeof(magic_abort_msg_t) + strlen(msg) + 1; void* map = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (map == MAP_FAILED) { diff --git a/libc/bionic/gwp_asan_wrappers.cpp b/libc/bionic/gwp_asan_wrappers.cpp index 8c513475d..79b4b69c7 100644 --- a/libc/bionic/gwp_asan_wrappers.cpp +++ b/libc/bionic/gwp_asan_wrappers.cpp @@ -144,10 +144,21 @@ size_t gwp_asan_malloc_usable_size(const void* mem) { } void* gwp_asan_realloc(void* old_mem, size_t bytes) { + // GPA::pointerIsMine(p) always returns false where `p == nullptr` (and thus + // malloc(bytes) is requested). We always fall back to the backing allocator, + // technically missing some coverage, but reducing an extra conditional + // branch. if (__predict_false(GuardedAlloc.pointerIsMine(old_mem))) { - size_t old_size = GuardedAlloc.getSize(old_mem); + if (__predict_false(bytes == 0)) { + GuardedAlloc.deallocate(old_mem); + return nullptr; + } void* new_ptr = gwp_asan_malloc(bytes); - if (new_ptr) memcpy(new_ptr, old_mem, (bytes < old_size) ? bytes : old_size); + // If malloc() fails, then don't destroy the old memory. + if (__predict_false(new_ptr == nullptr)) return nullptr; + + size_t old_size = GuardedAlloc.getSize(old_mem); + memcpy(new_ptr, old_mem, (bytes < old_size) ? bytes : old_size); GuardedAlloc.deallocate(old_mem); return new_ptr; } diff --git a/tests/Android.bp b/tests/Android.bp index 48149c7aa..2ea6087c3 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -343,6 +343,7 @@ cc_test_library { "__cxa_demangle_test.cpp", "alloca_test.cpp", "android_get_device_api_level.cpp", + "android_set_abort_message_test.cpp", "arpa_inet_test.cpp", "async_safe_test.cpp", "assert_test.cpp", diff --git a/tests/NOTICE b/tests/NOTICE index c9b65d07b..8c3483c3b 100644 --- a/tests/NOTICE +++ b/tests/NOTICE @@ -382,3 +382,31 @@ SUCH DAMAGE. ------------------------------------------------------------------- +Copyright (C) 2022 The Android Open Source Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +------------------------------------------------------------------- + diff --git a/tests/android_set_abort_message_test.cpp b/tests/android_set_abort_message_test.cpp new file mode 100644 index 000000000..d6553dedd --- /dev/null +++ b/tests/android_set_abort_message_test.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include <gtest/gtest.h> + +#if defined(__BIONIC__) +extern "C" void android_set_abort_message(const char* msg); +#endif + +TEST(android_set_abort_message_test, nullptr_check) { +#if defined(__BIONIC__) + android_set_abort_message(nullptr); +#else + GTEST_SKIP() << "This test is only supported on bionic."; +#endif +} |