[asan] add a run-time flag detect_container_overflow=true/false
llvm-svn: 206753
This commit is contained in:
parent
dd21b89a25
commit
38bb53b2c5
|
@ -63,6 +63,7 @@ struct Flags {
|
|||
bool strict_init_order;
|
||||
bool start_deactivated;
|
||||
int detect_invalid_pointer_pairs;
|
||||
bool detect_container_overflow;
|
||||
};
|
||||
|
||||
extern Flags asan_flags_dont_use_directly;
|
||||
|
|
|
@ -266,6 +266,7 @@ void __sanitizer_annotate_contiguous_container(const void *beg_p,
|
|||
const void *end_p,
|
||||
const void *old_mid_p,
|
||||
const void *new_mid_p) {
|
||||
if (!flags()->detect_container_overflow) return;
|
||||
VPrintf(2, "contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p,
|
||||
new_mid_p);
|
||||
uptr beg = reinterpret_cast<uptr>(beg_p);
|
||||
|
|
|
@ -141,7 +141,7 @@ static void PrintLegend(InternalScopedString *str) {
|
|||
kAsanInitializationOrderMagic);
|
||||
PrintShadowByte(str, " Poisoned by user: ",
|
||||
kAsanUserPoisonedMemoryMagic);
|
||||
PrintShadowByte(str, " Contiguous container OOB:",
|
||||
PrintShadowByte(str, " Container overflow: ",
|
||||
kAsanContiguousContainerOOBMagic);
|
||||
PrintShadowByte(str, " ASan internal: ", kAsanInternalHeapMagic);
|
||||
}
|
||||
|
|
|
@ -220,6 +220,11 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
|
|||
"If non-zero, try to detect operations like <, <=, >, >= and - on "
|
||||
"invalid pointer pairs (e.g. when pointers belong to different objects). "
|
||||
"The bigger the value the harder we try.");
|
||||
|
||||
ParseFlag(str, &f->detect_container_overflow,
|
||||
"detect_container_overflow",
|
||||
"If true, honor the container overflow annotations. "
|
||||
"See https://code.google.com/p/address-sanitizer/wiki/ContainerOverflow");
|
||||
}
|
||||
|
||||
void InitializeFlags(Flags *f, const char *env) {
|
||||
|
@ -267,6 +272,7 @@ void InitializeFlags(Flags *f, const char *env) {
|
|||
f->strict_init_order = false;
|
||||
f->start_deactivated = false;
|
||||
f->detect_invalid_pointer_pairs = 0;
|
||||
f->detect_container_overflow = true;
|
||||
|
||||
// Override from compile definition.
|
||||
ParseFlagsFromString(f, MaybeUseAsanDefaultOptionsCompileDefiniton());
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// RUN: %clangxx_asan -O %s -o %t
|
||||
// RUN: not %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
|
||||
// RUN: not %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD %s
|
||||
// RUN: ASAN_OPTIONS=detect_container_overflow=0 %t crash
|
||||
//
|
||||
// Test crash due to __sanitizer_annotate_contiguous_container.
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -16,6 +18,7 @@ static volatile int one = 1;
|
|||
|
||||
int TestCrash() {
|
||||
long t[100];
|
||||
t[60] = 0;
|
||||
__sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
|
||||
&t[0] + 50);
|
||||
return (int)t[60 * one]; // Touches the poisoned memory.
|
||||
|
|
Loading…
Reference in New Issue