From: Kostya Serebryany Date: Mon, 21 Dec 2015 19:22:26 +0000 (+0000) Subject: [asan] fix fopen interceptor to not crash if path is NULL X-Git-Tag: llvmorg-3.8.0-rc1~1421 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d1be3dd8822c18babbebdcc60d4bbf152df5607;p=platform%2Fupstream%2Fllvm.git [asan] fix fopen interceptor to not crash if path is NULL llvm-svn: 256182 --- diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index e56f6bf..4639ddc 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -4769,7 +4769,7 @@ INTERCEPTOR(int, __woverflow, __sanitizer_FILE *fp, int ch) { INTERCEPTOR(__sanitizer_FILE *, fopen, const char *path, const char *mode) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, fopen, path, mode); - COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1); + if (path) COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1); COMMON_INTERCEPTOR_READ_RANGE(ctx, mode, REAL(strlen)(mode) + 1); __sanitizer_FILE *res = REAL(fopen)(path, mode); COMMON_INTERCEPTOR_FILE_OPEN(ctx, res, path); diff --git a/compiler-rt/test/sanitizer_common/TestCases/fopen_nullptr.c b/compiler-rt/test/sanitizer_common/TestCases/fopen_nullptr.c new file mode 100644 index 0000000..960dda33 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/fopen_nullptr.c @@ -0,0 +1,6 @@ +// Check that fopen(NULL, "r") is ok. +// RUN: %clang -O2 %s -o %t && %run %t +#include +const char *fn = NULL; +FILE *f; +int main() { f = fopen(fn, "r"); }