File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -547,6 +547,7 @@ struct Allocator {
547547 ComputeUserRequestedAlignmentLog (alignment);
548548 if (alignment < min_alignment)
549549 alignment = min_alignment;
550+ bool upgraded_from_zero = false ;
550551 if (size == 0 ) {
551552 // We'd be happy to avoid allocating memory for zero-size requests, but
552553 // some programs/tests depend on this behavior and assume that malloc
@@ -555,6 +556,7 @@ struct Allocator {
555556 // consecutive "new" calls must be different even if the allocated size
556557 // is zero.
557558 size = 1 ;
559+ upgraded_from_zero = true ;
558560 }
559561 CHECK (IsPowerOfTwo (alignment));
560562 uptr rz_log = ComputeRZLog (size);
@@ -637,6 +639,10 @@ struct Allocator {
637639 *shadow = fl.poison_partial ? (size & (ASAN_SHADOW_GRANULARITY - 1 )) : 0 ;
638640 }
639641
642+ if (upgraded_from_zero)
643+ PoisonShadow (user_beg, ASAN_SHADOW_GRANULARITY,
644+ kAsanHeapLeftRedzoneMagic );
645+
640646 AsanStats &thread_stats = GetCurrentThreadStats ();
641647 thread_stats.mallocs ++;
642648 thread_stats.malloced += size;
Original file line number Diff line number Diff line change 11// RUN: %clang_asan -Wno-alloc-size -fsanitize-recover=address %s -o %t && %env_asan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s
22
3- // ASan doesn't catch this because internally it translates 0-byte allocations
4- // into 1-byte
5- // XFAIL: *
6-
73#include < malloc.h>
84#include < stdio.h>
95
You can’t perform that action at this time.
0 commit comments