[compiler-rt] fcf92cb - [tsan] Check for nullptr on user_alloc_usable_size_fast
Jin Xin Ng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 12 17:01:05 PDT 2023
Author: Jin Xin Ng
Date: 2023-06-13T00:00:31Z
New Revision: fcf92cb8008d802de4b64ae765fed1ffe3871a97
URL: https://github.com/llvm/llvm-project/commit/fcf92cb8008d802de4b64ae765fed1ffe3871a97
DIFF: https://github.com/llvm/llvm-project/commit/fcf92cb8008d802de4b64ae765fed1ffe3871a97.diff
LOG: [tsan] Check for nullptr on user_alloc_usable_size_fast
MBlock could be null (in the context of a call from RunFreeHooks)
if a static object was runtime initialized before tsan finished
initializing and that object later did a free().
While having the check isn't strictly required by
__sanitizer_get_allocated_size_fast's contract, a user's static object
would expect ptrs returned from malloc to be valid inputs.
Differential Revision: https://reviews.llvm.org/D152755
Added:
Modified:
compiler-rt/lib/tsan/rtl/tsan_mman.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
index ac6d005fc1c05..7b9dc81a3f6c3 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
@@ -379,6 +379,10 @@ uptr user_alloc_usable_size(const void *p) {
uptr user_alloc_usable_size_fast(const void *p) {
MBlock *b = ctx->metamap.GetBlock((uptr)p);
+ // Static objects may have malloc'd before tsan completes
+ // initialization, and may believe returned ptrs to be valid.
+ if (!b)
+ return 0; // Not a valid pointer.
if (b->siz == 0)
return 1; // Zero-sized allocations are actually 1 byte.
return b->siz;
More information about the llvm-commits
mailing list