[compiler-rt] 914f869 - [HWASAN] Fix Metadata::IsAllocatedMetadata::IsAllocated to return true even if the requested size is 0.

Kirill Stoimenov via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 15:48:02 PST 2023


Author: Kirill Stoimenov
Date: 2023-02-06T23:47:23Z
New Revision: 914f86949ae497953249fef8278d6eda8f5fae0d

URL: https://github.com/llvm/llvm-project/commit/914f86949ae497953249fef8278d6eda8f5fae0d
DIFF: https://github.com/llvm/llvm-project/commit/914f86949ae497953249fef8278d6eda8f5fae0d.diff

LOG: [HWASAN] Fix Metadata::IsAllocatedMetadata::IsAllocated to return true even if the requested size is 0.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D143438

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_allocator.cpp
    compiler-rt/test/lsan/TestCases/malloc_zero.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index a5f42dcbf55bb..9373ea2d6bad0 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -162,6 +162,9 @@ static uptr TaggedSize(uptr size) {
 
 static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
                             bool zeroise) {
+  // Keep this consistent with LSAN and ASAN behavior.
+  if (orig_size == 0)
+    orig_size = 1;
   if (orig_size > kMaxAllowedMallocSize) {
     if (AllocatorMayReturnNull()) {
       Report("WARNING: HWAddressSanitizer failed to allocate 0x%zx bytes\n",

diff  --git a/compiler-rt/test/lsan/TestCases/malloc_zero.c b/compiler-rt/test/lsan/TestCases/malloc_zero.c
index aadf25bf82924..5c8d1850a0f9a 100644
--- a/compiler-rt/test/lsan/TestCases/malloc_zero.c
+++ b/compiler-rt/test/lsan/TestCases/malloc_zero.c
@@ -1,9 +1,6 @@
 // RUN: %clang_lsan %s -o %t
 // RUN: %env_lsan_opts=use_stacks=0 not %run %t 2>&1 | FileCheck %s
 
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
 /// Fails when only leak sanitizer is enabled
 // UNSUPPORTED: arm-linux, armhf-linux
 


        


More information about the llvm-commits mailing list