summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-12-21 19:22:26 +0000
committerKostya Serebryany <kcc@google.com>2015-12-21 19:22:26 +0000
commit1d1be3dd8822c18babbebdcc60d4bbf152df5607 (patch)
tree186baee05706d18ac3b61c40bd9e741df8aeeb05
parent8614dd7e19f6d6730b9afe49137207b9ff412d66 (diff)
downloadbcm5719-llvm-1d1be3dd8822c18babbebdcc60d4bbf152df5607.tar.gz
bcm5719-llvm-1d1be3dd8822c18babbebdcc60d4bbf152df5607.zip
[asan] fix fopen interceptor to not crash if path is NULL
llvm-svn: 256182
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc2
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/fopen_nullptr.c6
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index e56f6bf7e95..4639ddc92c6 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 00000000000..960dda334a6
--- /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 <stdio.h>
+const char *fn = NULL;
+FILE *f;
+int main() { f = fopen(fn, "r"); }
OpenPOWER on IntegriCloud