[compiler-rt] r246435 - [asan] Fix the freopen interceptor to allow NULL instead of a filename

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 05:41:56 PDT 2015


Author: kuba.brecka
Date: Mon Aug 31 07:41:55 2015
New Revision: 246435

URL: http://llvm.org/viewvc/llvm-project?rev=246435&view=rev
Log:
[asan] Fix the freopen interceptor to allow NULL instead of a filename

According to `man freopen`, passing NULL instead of a filename is valid, however the current implementation of the interceptor assumes this parameter is non-NULL. Let's fix that and add a test case.

Differential Revision: http://reviews.llvm.org/D11389


Added:
    compiler-rt/trunk/test/asan/TestCases/Posix/freopen.cc
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=246435&r1=246434&r2=246435&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Aug 31 07:41:55 2015
@@ -4769,7 +4769,7 @@ INTERCEPTOR(__sanitizer_FILE *, freopen,
             __sanitizer_FILE *fp) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, freopen, path, mode, fp);
-  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);
   COMMON_INTERCEPTOR_FILE_CLOSE(ctx, fp);
   __sanitizer_FILE *res = REAL(freopen)(path, mode, fp);
@@ -4800,7 +4800,7 @@ INTERCEPTOR(__sanitizer_FILE *, freopen6
             __sanitizer_FILE *fp) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, freopen64, path, mode, fp);
-  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);
   COMMON_INTERCEPTOR_FILE_CLOSE(ctx, fp);
   __sanitizer_FILE *res = REAL(freopen64)(path, mode, fp);

Added: compiler-rt/trunk/test/asan/TestCases/Posix/freopen.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/freopen.cc?rev=246435&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/freopen.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/freopen.cc Mon Aug 31 07:41:55 2015
@@ -0,0 +1,15 @@
+// RUN: %clangxx_asan -O0 %s -o %t && %run %t
+
+// This fails on i386 Linux due to a glibc versioned symbols mixup.
+// REQUIRES: asan-64-bits
+
+#include <assert.h>
+#include <stdio.h>
+
+int main() {
+  FILE *fp = fopen("/dev/null", "w");
+  assert(fp);
+  freopen(NULL, "a", fp);
+  fclose(fp);
+  return 0;
+}




More information about the llvm-commits mailing list