[PATCH] D11389: [asan] Fix the freopen interceptor to allow NULL instead of a filename
Kuba Brecka
kuba.brecka at gmail.com
Tue Jul 21 07:04:24 PDT 2015
kubabrecka created this revision.
kubabrecka added reviewers: kcc, glider, samsonov.
kubabrecka added subscribers: llvm-commits, kcc, glider, samsonov, zaks.anna.
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.
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,11 @@
+// RUN: %clangxx_asan -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <stdio.h>
+
+int main() {
+ FILE *fp = fopen("/dev/null", "w");
+ assert(fp);
+ freopen(NULL, "a", fp);
+ fclose(fp);
+}
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -4671,7 +4671,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);
@@ -4702,7 +4702,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.30253.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150721/d9e9572b/attachment.bin>
More information about the llvm-commits
mailing list