aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2015-08-31 12:41:55 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2015-08-31 12:41:55 +0000
commitb79932addf6fac44be7675c51a8f24c7b38dce2d (patch)
tree7fb68f80cfa60521ae6e9762384684facb0e73cc
parentf506f41434be973a04502697b9681b85ff7ed48b (diff)
downloadllvm-b79932addf6fac44be7675c51a8f24c7b38dce2d.zip
llvm-b79932addf6fac44be7675c51a8f24c7b38dce2d.tar.gz
llvm-b79932addf6fac44be7675c51a8f24c7b38dce2d.tar.bz2
[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 llvm-svn: 246435
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc4
-rw-r--r--compiler-rt/test/asan/TestCases/Posix/freopen.cc15
2 files changed, 17 insertions, 2 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 6ad71a4..386c8a4 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(__sanitizer_FILE *, freopen, const char *path, const char *mode,
__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 *, freopen64, const char *path, const char *mode,
__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);
diff --git a/compiler-rt/test/asan/TestCases/Posix/freopen.cc b/compiler-rt/test/asan/TestCases/Posix/freopen.cc
new file mode 100644
index 0000000..c137abb
--- /dev/null
+++ b/compiler-rt/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;
+}