[compiler-rt] r256182 - [asan] fix fopen interceptor to not crash if path is NULL

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 11:22:27 PST 2015


Author: kcc
Date: Mon Dec 21 13:22:26 2015
New Revision: 256182

URL: http://llvm.org/viewvc/llvm-project?rev=256182&view=rev
Log:
[asan] fix fopen interceptor to not crash if path is NULL

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/fopen_nullptr.c
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=256182&r1=256181&r2=256182&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Dec 21 13:22:26 2015
@@ -4769,7 +4769,7 @@ INTERCEPTOR(int, __woverflow, __sanitize
 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);

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/fopen_nullptr.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/fopen_nullptr.c?rev=256182&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/fopen_nullptr.c (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/fopen_nullptr.c Mon Dec 21 13:22:26 2015
@@ -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"); }




More information about the llvm-commits mailing list