[asan] fix fopen interceptor to not crash if path is NULL

llvm-svn: 256182
This commit is contained in:
Kostya Serebryany 2015-12-21 19:22:26 +00:00
parent 8614dd7e19
commit 1d1be3dd88
2 changed files with 7 additions and 1 deletions

View File

@ -4769,7 +4769,7 @@ INTERCEPTOR(int, __woverflow, __sanitizer_FILE *fp, int ch) {
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);

View File

@ -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"); }