[compiler-rt] 99c7664 - asan: fix crash in strdup on malloc failure
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 20 06:37:34 PST 2023
Author: Dmitry Vyukov
Date: 2023-02-20T15:34:33+01:00
New Revision: 99c7664bd4be4a2e719415a18ca80fcf9a619a5e
URL: https://github.com/llvm/llvm-project/commit/99c7664bd4be4a2e719415a18ca80fcf9a619a5e
DIFF: https://github.com/llvm/llvm-project/commit/99c7664bd4be4a2e719415a18ca80fcf9a619a5e.diff
LOG: asan: fix crash in strdup on malloc failure
There are some programs that try to handle all malloc failures.
Let's allow testing of such programs.
Reviewed By: melver
Differential Revision: https://reviews.llvm.org/D144374
Added:
Modified:
compiler-rt/lib/asan/asan_interceptors.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 817008253fc0e..a4084c8d317f4 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -453,7 +453,9 @@ INTERCEPTOR(char*, strdup, const char *s) {
}
GET_STACK_TRACE_MALLOC;
void *new_mem = asan_malloc(length + 1, &stack);
- REAL(memcpy)(new_mem, s, length + 1);
+ if (new_mem) {
+ REAL(memcpy)(new_mem, s, length + 1);
+ }
return reinterpret_cast<char*>(new_mem);
}
@@ -469,7 +471,9 @@ INTERCEPTOR(char*, __strdup, const char *s) {
}
GET_STACK_TRACE_MALLOC;
void *new_mem = asan_malloc(length + 1, &stack);
- REAL(memcpy)(new_mem, s, length + 1);
+ if (new_mem) {
+ REAL(memcpy)(new_mem, s, length + 1);
+ }
return reinterpret_cast<char*>(new_mem);
}
#endif // ASAN_INTERCEPT___STRDUP
More information about the llvm-commits
mailing list