forked from OSchip/llvm-project
[ASan] fix a bug in allocator-v2 which could lead to SEGV on realloc(malloc(0), 4)
llvm-svn: 173681
This commit is contained in:
parent
20b09efabb
commit
7eda134fa7
|
@ -612,7 +612,7 @@ void *asan_calloc(uptr nmemb, uptr size, StackTrace *stack) {
|
|||
}
|
||||
|
||||
void *asan_realloc(void *p, uptr size, StackTrace *stack) {
|
||||
if (p == 0)
|
||||
if (p == 0 || reinterpret_cast<uptr>(p) == kReturnOnZeroMalloc)
|
||||
return Allocate(size, 8, stack, FROM_MALLOC);
|
||||
if (size == 0) {
|
||||
Deallocate(p, stack, FROM_MALLOC);
|
||||
|
|
|
@ -380,6 +380,15 @@ TEST(AddressSanitizer, ReallocTest) {
|
|||
(my_rand() % 1000 + kMinElem) * sizeof(int));
|
||||
EXPECT_EQ(3, ptr[3]);
|
||||
}
|
||||
free(ptr);
|
||||
// Realloc pointer returned by malloc(0).
|
||||
int *ptr2 = Ident((int*)malloc(0));
|
||||
fprintf(stderr, "Malloc(0): %p\n", ptr2);
|
||||
ptr2 = Ident((int*)realloc(ptr2, sizeof(*ptr2)));
|
||||
fprintf(stderr, "Realloc(0, 4): %p\n", ptr2);
|
||||
*ptr2 = 42;
|
||||
EXPECT_EQ(42, *ptr2);
|
||||
free(ptr2);
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
|
|
Loading…
Reference in New Issue