Skip to content

Commit 99c7664

Browse files
committed
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
1 parent c1bd1ee commit 99c7664

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ INTERCEPTOR(char*, strdup, const char *s) {
453453
}
454454
GET_STACK_TRACE_MALLOC;
455455
void *new_mem = asan_malloc(length + 1, &stack);
456-
REAL(memcpy)(new_mem, s, length + 1);
456+
if (new_mem) {
457+
REAL(memcpy)(new_mem, s, length + 1);
458+
}
457459
return reinterpret_cast<char*>(new_mem);
458460
}
459461

@@ -469,7 +471,9 @@ INTERCEPTOR(char*, __strdup, const char *s) {
469471
}
470472
GET_STACK_TRACE_MALLOC;
471473
void *new_mem = asan_malloc(length + 1, &stack);
472-
REAL(memcpy)(new_mem, s, length + 1);
474+
if (new_mem) {
475+
REAL(memcpy)(new_mem, s, length + 1);
476+
}
473477
return reinterpret_cast<char*>(new_mem);
474478
}
475479
#endif // ASAN_INTERCEPT___STRDUP

0 commit comments

Comments
 (0)