[sanitizer] Fix a crash in SizeClassAllocator32 with an out-of-range pointer

This happens on a 64-bit platform that uses SizeClassAllocator32 (e.g. ASan on AArch64). When querying a large invalid pointer, `__sanitizer_get_allocated_size(0xdeadbeefdeadbeef)`, an assertion will fail.  This patch changes PointerIsMine to return false if the pointer is outside of [kSpaceBeg, kSpaceBeg + kSpaceSize).

Differential Revision: http://reviews.llvm.org/D15008

llvm-svn: 268243
This commit is contained in:
Kuba Brecka 2016-05-02 15:23:01 +00:00
parent 0b75fd81e1
commit a90528bb89
2 changed files with 18 additions and 0 deletions

View File

@ -769,6 +769,9 @@ class SizeClassAllocator32 {
}
bool PointerIsMine(const void *p) {
uptr mem = reinterpret_cast<uptr>(p);
if (mem < kSpaceBeg || mem >= kSpaceBeg + kSpaceSize)
return false;
return GetSizeClass(p) != 0;
}

View File

@ -0,0 +1,15 @@
// RUN: %clang_asan %s -o %t -framework Foundation
// RUN: %run %t 2>&1 | FileCheck %s
#import <Foundation/Foundation.h>
#include <malloc/malloc.h>
int main(int argc, char *argv[]) {
id obj = @0;
fprintf(stderr, "obj = %p\n", obj);
size_t size = malloc_size(obj);
fprintf(stderr, "size = 0x%zx\n", size);
fprintf(stderr, "Done.\n");
// CHECK: Done.
return 0;
}