Skip to content

Commit 2455aca

Browse files
authored
Merge pull request #149 from apple/cherry-pick-48227136
Cherry pick 48227136
2 parents 9b87b25 + ddf3952 commit 2455aca

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,9 @@ INTERCEPTOR_WITH_SUFFIX(int, fputs, char *s, void *file) {
12411241
// libc file streams can call user-supplied functions, see fopencookie.
12421242
void *ctx;
12431243
COMMON_INTERCEPTOR_ENTER(ctx, fputs, s, file);
1244-
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
1244+
if (!SANITIZER_MAC || s) { // `fputs(NULL, file)` is supported on Darwin.
1245+
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
1246+
}
12451247
return REAL(fputs)(s, file);
12461248
}
12471249
#define INIT_FPUTS COMMON_INTERCEPT_FUNCTION(fputs)
@@ -1254,7 +1256,9 @@ INTERCEPTOR(int, puts, char *s) {
12541256
// libc file streams can call user-supplied functions, see fopencookie.
12551257
void *ctx;
12561258
COMMON_INTERCEPTOR_ENTER(ctx, puts, s);
1257-
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
1259+
if (!SANITIZER_MAC || s) { // `puts(NULL)` is supported on Darwin.
1260+
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
1261+
}
12581262
return REAL(puts)(s);
12591263
}
12601264
#define INIT_PUTS COMMON_INTERCEPT_FUNCTION(puts)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// On Darwin, the man page states that "both fputs() and puts() print `(null)'
2+
// if str is NULL."
3+
//
4+
// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
5+
// CHECK: {{^\(null\)---\(null\)$}}
6+
7+
#include <assert.h>
8+
#include <stdio.h>
9+
10+
int main(void) {
11+
assert(fputs(NULL, stdout) >= 0);
12+
fputs("---", stdout);
13+
assert(puts(NULL) >= 0);
14+
15+
return 0;
16+
}

0 commit comments

Comments
 (0)