diff options
author | Vy Nguyen <vyng@google.com> | 2021-03-12 11:35:50 -0500 |
---|---|---|
committer | Vy Nguyen <vyng@google.com> | 2021-03-12 11:35:50 -0500 |
commit | ab08c3865b37541ed1804f69196d61ecd5e1c3e6 (patch) | |
tree | 7e68b5b0a2cef67f3334799176913322ca32263f | |
parent | 731b3d766420ce05726174ff0e1527dca8a63791 (diff) | |
download | llvm-ab08c3865b37541ed1804f69196d61ecd5e1c3e6.zip llvm-ab08c3865b37541ed1804f69196d61ecd5e1c3e6.tar.gz llvm-ab08c3865b37541ed1804f69196d61ecd5e1c3e6.tar.bz2 |
Revert "Revert "[compiler-rt][asan] Make wild-pointer crash error more useful""
This reverts commit c578508b5bb20ccce5e2a43dd2afc41a49afec74.
Reland now that unrelated crash has been resolved.
-rw-r--r-- | compiler-rt/lib/asan/asan_descriptions.cpp | 9 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_descriptions.h | 13 | ||||
-rw-r--r-- | compiler-rt/test/asan/TestCases/wild_pointer.cpp | 22 |
3 files changed, 39 insertions, 5 deletions
diff --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp index 153c874..347eaa4 100644 --- a/compiler-rt/lib/asan/asan_descriptions.cpp +++ b/compiler-rt/lib/asan/asan_descriptions.cpp @@ -77,7 +77,6 @@ static bool GetShadowKind(uptr addr, ShadowKind *shadow_kind) { } else if (AddrIsInLowShadow(addr)) { *shadow_kind = kShadowKindLow; } else { - CHECK(0 && "Address is not in memory and not in shadow?"); return false; } return true; @@ -464,7 +463,13 @@ AddressDescription::AddressDescription(uptr addr, uptr access_size, return; } data.kind = kAddressKindWild; - addr = 0; + data.wild.addr = addr; + data.wild.access_size = access_size; +} + +void WildAddressDescription::Print() const { + Printf("Address %p is a wild pointer inside of access range of size %p.\n", + addr, access_size); } void PrintAddressDescription(uptr addr, uptr access_size, diff --git a/compiler-rt/lib/asan/asan_descriptions.h b/compiler-rt/lib/asan/asan_descriptions.h index ee0e206..650e2eb 100644 --- a/compiler-rt/lib/asan/asan_descriptions.h +++ b/compiler-rt/lib/asan/asan_descriptions.h @@ -146,6 +146,13 @@ struct StackAddressDescription { bool GetStackAddressInformation(uptr addr, uptr access_size, StackAddressDescription *descr); +struct WildAddressDescription { + uptr addr; + uptr access_size; + + void Print() const; +}; + struct GlobalAddressDescription { uptr addr; // Assume address is close to at most four globals. @@ -193,7 +200,7 @@ class AddressDescription { HeapAddressDescription heap; StackAddressDescription stack; GlobalAddressDescription global; - uptr addr; + WildAddressDescription wild; }; }; @@ -211,7 +218,7 @@ class AddressDescription { uptr Address() const { switch (data.kind) { case kAddressKindWild: - return data.addr; + return data.wild.addr; case kAddressKindShadow: return data.shadow.addr; case kAddressKindHeap: @@ -226,7 +233,7 @@ class AddressDescription { void Print(const char *bug_descr = nullptr) const { switch (data.kind) { case kAddressKindWild: - Printf("Address %p is a wild pointer.\n", data.addr); + data.wild.Print(); return; case kAddressKindShadow: return data.shadow.Print(); diff --git a/compiler-rt/test/asan/TestCases/wild_pointer.cpp b/compiler-rt/test/asan/TestCases/wild_pointer.cpp new file mode 100644 index 0000000..80c3e2b --- /dev/null +++ b/compiler-rt/test/asan/TestCases/wild_pointer.cpp @@ -0,0 +1,22 @@ +// RUN: %clangxx_asan %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s +// REQUIRES: asan-64-bits + +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +int main() { + char *p = new char; + char *dest = new char; + const size_t offset = 0x4567890123456789; + // Flush it so the output came out before the asan report. + fprintf(stderr, "Expected bad addr: %p\n", p + offset); + fflush(stderr); + memmove(dest, p, offset); + return 0; +} + +// CHECK: Expected bad addr: [[ADDR:0x[0-9,a-f]+]] +// CHECK: AddressSanitizer: unknown-crash on address [[ADDR]] +// CHECK: Address [[ADDR]] is a wild pointer inside of access range of size 0x4567890123456789 |