File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -605,10 +605,13 @@ static void PrintShadowMemoryForAddress(uptr addr) {
605
605
static void CheckPoisonRecords (uptr addr) {
606
606
if (!AddrIsInMem (addr))
607
607
return ;
608
- uptr shadow_addr = MemToShadow (addr);
609
- unsigned char poison_magic = *(reinterpret_cast <u8 *>(shadow_addr));
610
608
611
- if (poison_magic != kAsanUserPoisonedMemoryMagic )
609
+ u8 *shadow_addr = (u8 *)MemToShadow (addr);
610
+ // If we are in the partial right redzone, look at the next shadow byte.
611
+ if (*shadow_addr > 0 && *shadow_addr < 128 ) shadow_addr++;
612
+ u8 shadow_val = *shadow_addr;
613
+
614
+ if (shadow_val != kAsanUserPoisonedMemoryMagic )
612
615
return ;
613
616
614
617
Printf (" \n " );
Original file line number Diff line number Diff line change
1
+ // Check that __asan_poison_memory_region and ASAN_OPTIONS=poison_history_size work.
2
+ //
3
+ // RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 20 2>&1 | FileCheck %s
4
+ //
5
+ // Partial granule
6
+ // RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 2>&1 | FileCheck %s
7
+
8
+ #include < stdio.h>
9
+ #include < stdlib.h>
10
+
11
+ extern " C" void __asan_poison_memory_region (void *, size_t );
12
+ extern " C" void __asan_unpoison_memory_region (void *, size_t );
13
+
14
+ void honey_ive_poisoned_the_memory (char *x) {
15
+ __asan_poison_memory_region (x + 10 , 20 );
16
+ }
17
+
18
+ void foo (char *x) { honey_ive_poisoned_the_memory (x); }
19
+
20
+ int main (int argc, char **argv) {
21
+ char *x = new char [64 ];
22
+ x[10 ] = 0 ;
23
+ foo (x);
24
+ // Bytes [0, 9]: addressable
25
+ // Bytes [10, 31]: poisoned by A
26
+ // Bytes [32, 63]: addressable
27
+
28
+ int res = x[argc * 10 ]; // BOOOM
29
+ // CHECK: ERROR: AddressSanitizer: use-after-poison
30
+ // CHECK: main{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-2]]
31
+
32
+ // CHECK: Memory was manually poisoned by thread T0:
33
+ // CHECK: honey_ive_poisoned_the_memory{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-18]]
34
+ // CHECK: foo{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-16]]
35
+ // CHECK: main{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-12]]
36
+
37
+ delete[] x;
38
+
39
+ return 0 ;
40
+ }
You can’t perform that action at this time.
0 commit comments