[compiler-rt] [compiler-rt][tysan] adding posix strndup interception. (PR #122255)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 9 03:34:57 PST 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/122255.diff
1 Files Affected:
- (modified) compiler-rt/lib/tysan/tysan_interceptors.cpp (+15)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/122255
More information about the llvm-commits
mailing list