[compiler-rt] [compiler-rt] setproctitle interception for NetBSD/FreeBSD. (PR #131648)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 17 10:38:27 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: David CARLIER (devnexen)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/131648.diff
3 Files Affected:
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc (+18)
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h (+2)
- (added) compiler-rt/test/sanitizer_common/TestCases/Posix/setproctitle.c (+12)
``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 24a8a2d4dc55b..47b4ea5351e40 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1855,6 +1855,23 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_snprintf, __isoc99_vsnprintf, str, size,
#define INIT_ISOC99_PRINTF
#endif
+#if SANITIZER_INTERCEPT_SETPROCTITLE
+INTERCEPTOR(void, setproctitle, const char *fmt, ...)
+{
+ void *ctx;
+ va_list ap;
+ va_start(ap, fmt);
+ COMMON_INTERCEPTOR_ENTER(ctx, setproctitle, fmt, ap);
+ if (common_flags()->check_printf)
+ printf_common(ctx, fmt, ap);
+ REAL(setproctitle)(fmt, ap);
+ va_end(ap);
+}
+#define INIT_SETPROCTITLE COMMON_INTERCEPT_FUNCTION(setproctitle);
+#else
+#define INIT_SETPROCTITLE
+#endif
+
#if SANITIZER_INTERCEPT_IOCTL
#include "sanitizer_common_interceptors_ioctl.inc"
#include "sanitizer_interceptors_ioctl_netbsd.inc"
@@ -10328,6 +10345,7 @@ static void InitializeCommonInterceptors() {
INIT_PRINTF;
INIT_PRINTF_L;
INIT_ISOC99_PRINTF;
+ INIT_SETPROCTITLE;
INIT_FREXP;
INIT_FREXPF_FREXPL;
INIT_GETPWNAM_AND_FRIENDS;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index e52f131e26b1a..468b5494d0092 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -238,6 +238,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
#define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
#endif
+#define SANITIZER_INTERCEPT_SETPROCTITLE (SI_FREEBSD || SI_NETBSD)
+
#define SANITIZER_INTERCEPT___PRINTF_CHK \
(SANITIZER_INTERCEPT_PRINTF && SI_GLIBC)
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/setproctitle.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/setproctitle.c
new file mode 100644
index 0000000000000..3182391bd430f
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/setproctitle.c
@@ -0,0 +1,12 @@
+// RUN: %clang_asan -O2 %s -o %t
+// RUN: %env_asan_opts=check_printf=1 %run %t 2>&1
+
+// REQUIRES: freebsd || netbsd
+
+#include <unistd.h>
+
+int main() {
+ setproctitle("%s", "setproctitle");
+ setproctitle("%c%c%c", 'c', 0, 'e');
+ return 0;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/131648
More information about the llvm-commits
mailing list