Skip to content

Commit b4c840e

Browse files
committed
[Sanitizers] intercept hexdump on FreeBSD.
Reviewers: vitalybuka Reviewed-By: vitalybuka Differential Revision: https://reviews.llvm.org/D110471
1 parent a63fd9d commit b4c840e

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10357,6 +10357,20 @@ INTERCEPTOR(int, __xuname, int size, void *utsname) {
1035710357
#define INIT___XUNAME
1035810358
#endif
1035910359

10360+
#if SANITIZER_INTERCEPT_HEXDUMP
10361+
INTERCEPTOR(void, hexdump, const void *ptr, int length, const char *header, int flags) {
10362+
void *ctx;
10363+
COMMON_INTERCEPTOR_ENTER(ctx, hexdump, ptr, length, header, flags);
10364+
COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, length);
10365+
COMMON_INTERCEPTOR_READ_RANGE(ctx, header, internal_strlen(header) + 1);
10366+
REAL(hexdump)(ptr, length, header, flags);
10367+
}
10368+
10369+
#define INIT_HEXDUMP COMMON_INTERCEPT_FUNCTION(hexdump);
10370+
#else
10371+
#define INIT_HEXDUMP
10372+
#endif
10373+
1036010374
#include "sanitizer_common_interceptors_netbsd_compat.inc"
1036110375

1036210376
static void InitializeCommonInterceptors() {
@@ -10675,6 +10689,7 @@ static void InitializeCommonInterceptors() {
1067510689
INIT_PROCCTL
1067610690
INIT_UNAME;
1067710691
INIT___XUNAME;
10692+
INIT_HEXDUMP;
1067810693

1067910694
INIT___PRINTF_CHK;
1068010695
}

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@
591591
#define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD
592592
#define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD
593593
#define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
594+
#define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
594595

595596
// This macro gives a way for downstream users to override the above
596597
// interceptor macros irrespective of the platform they are on. They have
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clangxx -O0 -g %s -o %t -lutil && %run %t 2>&1 | FileCheck %s
2+
3+
#include <assert.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <libutil.h>
7+
8+
int main(void) {
9+
printf("hexdump");
10+
char *line;
11+
size_t lineno = 0, len;
12+
const char *delim = "\\\\#";
13+
FILE *fp = fopen("/etc/fstab", "r");
14+
assert(fp);
15+
line = fparseln(fp, &len, &lineno, delim, 0);
16+
hexdump(line, len, nullptr, 0);
17+
free(line);
18+
fclose(fp);
19+
assert(lineno != 0);
20+
assert(len > 0);
21+
22+
return 0;
23+
}

0 commit comments

Comments
 (0)