summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2018-08-31 01:38:00 +0000
committerKostya Serebryany <kcc@google.com>2018-08-31 01:38:00 +0000
commitc5ef5718e98fc3c53adf5961a484c0546ff38359 (patch)
tree88b0a54f6c8b8f4b24fa22072b71d97864e9a2f5
parentbdd3a3bdaf966d452458455c9cda7c89cbb41e3a (diff)
downloadcompiler-rt-c5ef5718e98fc3c53adf5961a484c0546ff38359.tar.gz
[hwasan] make malloc(0) return nullptr, add basic address description for stack addresses
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@341156 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/hwasan/hwasan_allocator.cc1
-rw-r--r--lib/hwasan/hwasan_report.cc6
-rw-r--r--test/hwasan/TestCases/malloc-test.c13
-rw-r--r--test/hwasan/TestCases/realloc-test.cc2
-rw-r--r--test/hwasan/TestCases/stack-oob.cc2
-rw-r--r--test/hwasan/TestCases/stack-uar.cc2
6 files changed, 24 insertions, 2 deletions
diff --git a/lib/hwasan/hwasan_allocator.cc b/lib/hwasan/hwasan_allocator.cc
index c531a4201..6b62b6a34 100644
--- a/lib/hwasan/hwasan_allocator.cc
+++ b/lib/hwasan/hwasan_allocator.cc
@@ -121,6 +121,7 @@ void HwasanThreadLocalMallocStorage::CommitBack() {
static void *HwasanAllocate(StackTrace *stack, uptr size, uptr alignment,
bool zeroise) {
+ if (!size) return nullptr;
alignment = Max(alignment, kShadowAlignment);
size = RoundUpTo(size, kShadowAlignment);
diff --git a/lib/hwasan/hwasan_report.cc b/lib/hwasan/hwasan_report.cc
index 3d333fff5..807d73940 100644
--- a/lib/hwasan/hwasan_report.cc
+++ b/lib/hwasan/hwasan_report.cc
@@ -84,6 +84,12 @@ void PrintAddressDescription(uptr tagged_addr, uptr access_size) {
num_descriptions_printed++;
}
+ if (t->AddrIsInStack(untagged_addr)) {
+ Printf("%s", d.Location());
+ Printf("Address %p is located in stack of thread %p\n", untagged_addr, t);
+ Printf("%s", d.Default());
+ num_descriptions_printed++;
+ }
});
if (!num_descriptions_printed)
diff --git a/test/hwasan/TestCases/malloc-test.c b/test/hwasan/TestCases/malloc-test.c
new file mode 100644
index 000000000..13d04e6f2
--- /dev/null
+++ b/test/hwasan/TestCases/malloc-test.c
@@ -0,0 +1,13 @@
+// Test basic malloc functionality.
+// RUN: %clang_hwasan %s -o %t
+// RUN: %run %t
+
+#include <stdlib.h>
+#include <assert.h>
+#include <sanitizer/hwasan_interface.h>
+
+int main() {
+ __hwasan_enable_allocator_tagging();
+ char *a1 = (char*)malloc(0);
+ assert(a1 == NULL); // may not be true for other malloc.
+}
diff --git a/test/hwasan/TestCases/realloc-test.cc b/test/hwasan/TestCases/realloc-test.cc
index 23bc61923..838790242 100644
--- a/test/hwasan/TestCases/realloc-test.cc
+++ b/test/hwasan/TestCases/realloc-test.cc
@@ -4,8 +4,10 @@
#include <stdlib.h>
#include <assert.h>
+#include <sanitizer/hwasan_interface.h>
int main() {
+ __hwasan_enable_allocator_tagging();
char *x = (char*)realloc(nullptr, 4);
x[0] = 10;
x[1] = 20;
diff --git a/test/hwasan/TestCases/stack-oob.cc b/test/hwasan/TestCases/stack-oob.cc
index 60b9a6295..caa0de3bc 100644
--- a/test/hwasan/TestCases/stack-oob.cc
+++ b/test/hwasan/TestCases/stack-oob.cc
@@ -19,7 +19,7 @@ int main() {
// CHECK: READ of size 1 at
// CHECK: #0 {{.*}} in f{{.*}}stack-oob.cc:14
- // CHECK: HWAddressSanitizer can not describe address in more detail.
+ // CHECK: is located in stack of threa
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in f
}
diff --git a/test/hwasan/TestCases/stack-uar.cc b/test/hwasan/TestCases/stack-uar.cc
index e99dcceed..b2bf1e1b5 100644
--- a/test/hwasan/TestCases/stack-uar.cc
+++ b/test/hwasan/TestCases/stack-uar.cc
@@ -17,7 +17,7 @@ int main() {
// CHECK: READ of size 1 at
// CHECK: #0 {{.*}} in main{{.*}}stack-uar.cc:16
- // CHECK: HWAddressSanitizer can not describe address in more detail.
+ // CHECK: is located in stack of thread
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
}