forked from OSchip/llvm-project
parent
49b88f54da
commit
632751539e
|
@ -355,23 +355,7 @@ INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
|
|||
return REAL(memcmp(a1, a2, size));
|
||||
}
|
||||
|
||||
#define MEMMOVE_BODY { \
|
||||
if (!asan_inited) return internal_memmove(to, from, size); \
|
||||
if (asan_init_is_running) { \
|
||||
return REAL(memmove)(to, from, size); \
|
||||
} \
|
||||
ENSURE_ASAN_INITED(); \
|
||||
if (flags()->replace_intrin) { \
|
||||
ASAN_READ_RANGE(from, size); \
|
||||
ASAN_WRITE_RANGE(to, size); \
|
||||
} \
|
||||
return internal_memmove(to, from, size); \
|
||||
}
|
||||
|
||||
INTERCEPTOR(void*, memmove, void *to, const void *from, uptr size) MEMMOVE_BODY
|
||||
|
||||
INTERCEPTOR(void*, memcpy, void *to, const void *from, uptr size) {
|
||||
#if !SANITIZER_MAC
|
||||
void *__asan_memcpy(void *to, const void *from, uptr size) {
|
||||
if (!asan_inited) return internal_memcpy(to, from, size);
|
||||
// memcpy is called during __asan_init() from the internals
|
||||
// of printf(...).
|
||||
|
@ -389,18 +373,9 @@ INTERCEPTOR(void*, memcpy, void *to, const void *from, uptr size) {
|
|||
ASAN_WRITE_RANGE(to, size);
|
||||
}
|
||||
return REAL(memcpy)(to, from, size);
|
||||
#else
|
||||
// At least on 10.7 and 10.8 both memcpy() and memmove() are being replaced
|
||||
// with WRAP(memcpy). As a result, false positives are reported for memmove()
|
||||
// calls. If we just disable error reporting with
|
||||
// ASAN_OPTIONS=replace_intrin=0, memmove() is still replaced with
|
||||
// internal_memcpy(), which may lead to crashes, see
|
||||
// http://llvm.org/bugs/show_bug.cgi?id=16362.
|
||||
MEMMOVE_BODY
|
||||
#endif // !SANITIZER_MAC
|
||||
}
|
||||
|
||||
INTERCEPTOR(void*, memset, void *block, int c, uptr size) {
|
||||
void *__asan_memset(void *block, int c, uptr size) {
|
||||
if (!asan_inited) return internal_memset(block, c, size);
|
||||
// memset is called inside Printf.
|
||||
if (asan_init_is_running) {
|
||||
|
@ -413,6 +388,39 @@ INTERCEPTOR(void*, memset, void *block, int c, uptr size) {
|
|||
return REAL(memset)(block, c, size);
|
||||
}
|
||||
|
||||
void *__asan_memmove(void *to, const void *from, uptr size) {
|
||||
if (!asan_inited)
|
||||
return internal_memmove(to, from, size);
|
||||
ENSURE_ASAN_INITED();
|
||||
if (flags()->replace_intrin) {
|
||||
ASAN_READ_RANGE(from, size);
|
||||
ASAN_WRITE_RANGE(to, size);
|
||||
}
|
||||
return internal_memmove(to, from, size);
|
||||
}
|
||||
|
||||
INTERCEPTOR(void*, memmove, void *to, const void *from, uptr size) {
|
||||
return __asan_memmove(to, from, size);
|
||||
}
|
||||
|
||||
INTERCEPTOR(void*, memcpy, void *to, const void *from, uptr size) {
|
||||
#if !SANITIZER_MAC
|
||||
return __asan_memcpy(to, from, size);
|
||||
#else
|
||||
// At least on 10.7 and 10.8 both memcpy() and memmove() are being replaced
|
||||
// with WRAP(memcpy). As a result, false positives are reported for memmove()
|
||||
// calls. If we just disable error reporting with
|
||||
// ASAN_OPTIONS=replace_intrin=0, memmove() is still replaced with
|
||||
// internal_memcpy(), which may lead to crashes, see
|
||||
// http://llvm.org/bugs/show_bug.cgi?id=16362.
|
||||
return __asan_memmove(to, from, size);
|
||||
#endif // !SANITIZER_MAC
|
||||
}
|
||||
|
||||
INTERCEPTOR(void*, memset, void *block, int c, uptr size) {
|
||||
return __asan_memset(block, c, size);
|
||||
}
|
||||
|
||||
INTERCEPTOR(char*, strchr, const char *str, int c) {
|
||||
if (!asan_inited) return internal_strchr(str, c);
|
||||
// strchr is called inside create_purgeable_zone() when MallocGuardEdges=1 is
|
||||
|
|
|
@ -137,6 +137,13 @@ extern "C" {
|
|||
SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void* __asan_memcpy(void *dst, const void *src, uptr size);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void* __asan_memset(void *s, int c, uptr n);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void* __asan_memmove(void* dest, const void* src, uptr n);
|
||||
} // extern "C"
|
||||
|
||||
#endif // ASAN_INTERFACE_INTERNAL_H
|
||||
|
|
|
@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {
|
|||
my_memset(buf, 11);
|
||||
// CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
|
||||
// CHECK: {{WRITE of size 11 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in my_memset .*interception-in-shared-lib-test.cc:17}}
|
||||
// CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:17}}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue