Skip to content

Commit 2d56e13

Browse files
committed
[Sanitizer] Intercepts flopen/flopenat on FreeBSD.
Reviewers: vitalybuka Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D106218
1 parent 9333d34 commit 2d56e13

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

+35
Original file line numberDiff line numberDiff line change
@@ -6104,6 +6104,40 @@ INTERCEPTOR(__sanitizer_FILE *, freopen, const char *path, const char *mode,
61046104
#define INIT_FOPEN
61056105
#endif
61066106

6107+
#if SANITIZER_INTERCEPT_FLOPEN
6108+
INTERCEPTOR(int, flopen, const char *path, int flags, ...) {
6109+
void *ctx;
6110+
va_list ap;
6111+
va_start(ap, flags);
6112+
u16 mode = static_cast<u16>(va_arg(ap, u32));
6113+
va_end(ap);
6114+
COMMON_INTERCEPTOR_ENTER(ctx, flopen, path, flags, mode);
6115+
if (path) {
6116+
COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
6117+
}
6118+
return REAL(flopen)(path, flags, mode);
6119+
}
6120+
6121+
INTERCEPTOR(int, flopenat, int dirfd, const char *path, int flags, ...) {
6122+
void *ctx;
6123+
va_list ap;
6124+
va_start(ap, flags);
6125+
u16 mode = static_cast<u16>(va_arg(ap, u32));
6126+
va_end(ap);
6127+
COMMON_INTERCEPTOR_ENTER(ctx, flopen, path, flags, mode);
6128+
if (path) {
6129+
COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
6130+
}
6131+
return REAL(flopenat)(dirfd, path, flags, mode);
6132+
}
6133+
6134+
#define INIT_FLOPEN \
6135+
COMMON_INTERCEPT_FUNCTION(flopen); \
6136+
COMMON_INTERCEPT_FUNCTION(flopenat);
6137+
#else
6138+
#define INIT_FLOPEN
6139+
#endif
6140+
61076141
#if SANITIZER_INTERCEPT_FOPEN64
61086142
INTERCEPTOR(__sanitizer_FILE *, fopen64, const char *path, const char *mode) {
61096143
void *ctx;
@@ -10269,6 +10303,7 @@ static void InitializeCommonInterceptors() {
1026910303
INIT_LIBIO_INTERNALS;
1027010304
INIT_FOPEN;
1027110305
INIT_FOPEN64;
10306+
INIT_FLOPEN;
1027210307
INIT_OPEN_MEMSTREAM;
1027310308
INIT_OBSTACK;
1027410309
INIT_FFLUSH;

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@
577577
(SI_POSIX && !(SANITIZER_MAC && SANITIZER_I386))
578578
#define SANITIZER_INTERCEPT_UNAME (SI_POSIX && !SI_FREEBSD)
579579
#define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD
580+
#define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD
580581

581582
// This macro gives a way for downstream users to override the above
582583
// interceptor macros irrespective of the platform they are on. They have

0 commit comments

Comments
 (0)