[compiler-rt] [compiler-rt][tysan] adding posix strndup interception. (PR #122255)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 9 03:34:26 PST 2025
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/122255
None
>From 1bf6954a353ee4a9a484d22248dd055699e7c81c Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Thu, 9 Jan 2025 11:33:38 +0000
Subject: [PATCH] [compiler-rt][tysan] adding posix strndup interception.
---
compiler-rt/lib/tysan/tysan_interceptors.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/compiler-rt/lib/tysan/tysan_interceptors.cpp b/compiler-rt/lib/tysan/tysan_interceptors.cpp
index 08b1010a48ecf0..2dd4f1d8271f97 100644
--- a/compiler-rt/lib/tysan/tysan_interceptors.cpp
+++ b/compiler-rt/lib/tysan/tysan_interceptors.cpp
@@ -22,6 +22,12 @@
#define TYSAN_INTERCEPT___STRDUP 0
#endif
+#if SANITIZER_POSIX
+#define TYSAN_INTERCEPT___STRNDUP 1
+#else
+#define TYSAN_INTERCEPT___STRNDUP 0
+#endif
+
#if SANITIZER_LINUX
extern "C" int mallopt(int param, int value);
#endif
@@ -99,6 +105,15 @@ INTERCEPTOR(char *, __strdup, const char *s) {
}
#endif // TYSAN_INTERCEPT___STRDUP
+#if TYSAN_INTERCEPT___STRNDUP
+INTERCEPTOR(char *, strndup, const char *s, SIZE_T slen) {
+ char *res = REAL(strndup)(s, slen);
+ if (res)
+ tysan_copy_types(res, const_cast<char *>(s), Min(internal_strlen(s), slen));
+ return res;
+}
+#endif
+
INTERCEPTOR(void *, malloc, uptr size) {
if (DlsymAlloc::Use())
return DlsymAlloc::Allocate(size);
More information about the llvm-commits
mailing list