[HWASAN] Fix Metadata::IsAllocatedMetadata::IsAllocated to return true even if the...
authorKirill Stoimenov <kstoimenov@google.com>
Mon, 6 Feb 2023 22:41:20 +0000 (22:41 +0000)
committerKirill Stoimenov <kstoimenov@google.com>
Mon, 6 Feb 2023 23:47:23 +0000 (23:47 +0000)
Reviewed By: MaskRay

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

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

index a5f42dc..9373ea2 100644 (file)
@@ -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",
index aadf25b..5c8d185 100644 (file)
@@ -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