[PATCH] D11389: [asan] Fix the freopen interceptor to allow NULL instead of a filename

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 10:28:36 PDT 2015


kubabrecka updated this revision to Diff 33337.
kubabrecka added a comment.

Marking the patch with `REQUIRES: asan-64-bits` to skip the test on i386 Linux (where it fails due to an unrelated issue with glibc versioned symbols).  `XFAIL` wouldn't work here, because the test actually passes on all other platforms/architectures.


http://reviews.llvm.org/D11389

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  test/asan/TestCases/Posix/freopen.cc

Index: test/asan/TestCases/Posix/freopen.cc
===================================================================
--- test/asan/TestCases/Posix/freopen.cc
+++ test/asan/TestCases/Posix/freopen.cc
@@ -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;
+}
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -4761,7 +4761,7 @@
             __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);
@@ -4792,7 +4792,7 @@
             __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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11389.33337.patch
Type: text/x-patch
Size: 1679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150827/9169af1b/attachment.bin>


More information about the llvm-commits mailing list