diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -10357,6 +10357,20 @@ #define INIT___XUNAME #endif +#if SANITIZER_INTERCEPT_HEXDUMP +INTERCEPTOR(void, hexdump, const void *ptr, int length, const char *header, int flags) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, hexdump, ptr, length, header, flags); + COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, length); + COMMON_INTERCEPTOR_READ_RANGE(ctx, header, internal_strlen(header) + 1); + REAL(hexdump)(ptr, length, header, flags); +} + +#define INIT_HEXDUMP COMMON_INTERCEPT_FUNCTION(hexdump); +#else +#define INIT_HEXDUMP +#endif + #include "sanitizer_common_interceptors_netbsd_compat.inc" static void InitializeCommonInterceptors() { @@ -10675,6 +10689,7 @@ INIT_PROCCTL INIT_UNAME; INIT___XUNAME; + INIT_HEXDUMP; INIT___PRINTF_CHK; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -591,6 +591,7 @@ #define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD #define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD #define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD +#define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD // This macro gives a way for downstream users to override the above // interceptor macros irrespective of the platform they are on. They have diff --git a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc new file mode 100644 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -O0 -g %s -o %t -lutil && %run %t 2>&1 | FileCheck %s + +#include +#include +#include +#include + +int main(void) { + printf("hexdump"); + char *line; + size_t lineno = 0, len; + const char *delim = "\\\\#"; + FILE *fp = fopen("/etc/fstab", "r"); + assert(fp); + line = fparseln(fp, &len, &lineno, delim, 0); + hexdump(line, len, nullptr, 0); + free(line); + fclose(fp); + assert(lineno != 0); + assert(len > 0); + + return 0; +}