summaryrefslogtreecommitdiff
path: root/lib/msan/msan_interceptors.cc
diff options
context:
space:
mode:
authorPierre Gousseau <pierregousseau14@gmail.com>2017-05-02 10:22:05 +0000
committerPierre Gousseau <pierregousseau14@gmail.com>2017-05-02 10:22:05 +0000
commita09710f1e54c089241210527d2814f588d73b0be (patch)
tree1bad5ed17df1e3548401a506020f30f51a86079f /lib/msan/msan_interceptors.cc
parent25469d9bd4174709ad3c4b85dadfa7892ebf3171 (diff)
Revert r301904 causing tsan test failure in x86_64-linux-autoconf
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/msan/msan_interceptors.cc')
-rw-r--r--lib/msan/msan_interceptors.cc36
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc
index 0f5069344..15543bd91 100644
--- a/lib/msan/msan_interceptors.cc
+++ b/lib/msan/msan_interceptors.cc
@@ -341,6 +341,33 @@ INTERCEPTOR(char *, __strdup, char *src) {
#define MSAN_MAYBE_INTERCEPT___STRDUP
#endif
+INTERCEPTOR(char *, strndup, char *src, SIZE_T n) {
+ ENSURE_MSAN_INITED();
+ GET_STORE_STACK_TRACE;
+ // On FreeBSD strndup() leverages strnlen().
+ InterceptorScope interceptor_scope;
+ SIZE_T copy_size = REAL(strnlen)(src, n);
+ char *res = REAL(strndup)(src, n);
+ CopyShadowAndOrigin(res, src, copy_size, &stack);
+ __msan_unpoison(res + copy_size, 1); // \0
+ return res;
+}
+
+#if !SANITIZER_FREEBSD
+INTERCEPTOR(char *, __strndup, char *src, SIZE_T n) {
+ ENSURE_MSAN_INITED();
+ GET_STORE_STACK_TRACE;
+ SIZE_T copy_size = REAL(strnlen)(src, n);
+ char *res = REAL(__strndup)(src, n);
+ CopyShadowAndOrigin(res, src, copy_size, &stack);
+ __msan_unpoison(res + copy_size, 1); // \0
+ return res;
+}
+#define MSAN_MAYBE_INTERCEPT___STRNDUP INTERCEPT_FUNCTION(__strndup)
+#else
+#define MSAN_MAYBE_INTERCEPT___STRNDUP
+#endif
+
INTERCEPTOR(char *, gcvt, double number, SIZE_T ndigit, char *buf) {
ENSURE_MSAN_INITED();
char *res = REAL(gcvt)(number, ndigit, buf);
@@ -1344,13 +1371,6 @@ int OnExit() {
return __msan_memcpy(to, from, size); \
}
-#define COMMON_INTERCEPTOR_COPY_STRING(ctx, to, from, size) \
- do { \
- GET_STORE_STACK_TRACE; \
- CopyShadowAndOrigin(to, from, size, &stack); \
- __msan_unpoison(to + size, 1); \
- } while (false)
-
#include "sanitizer_common/sanitizer_platform_interceptors.h"
#include "sanitizer_common/sanitizer_common_interceptors.inc"
@@ -1518,6 +1538,8 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(stpcpy); // NOLINT
INTERCEPT_FUNCTION(strdup);
MSAN_MAYBE_INTERCEPT___STRDUP;
+ INTERCEPT_FUNCTION(strndup);
+ MSAN_MAYBE_INTERCEPT___STRNDUP;
INTERCEPT_FUNCTION(strncpy); // NOLINT
INTERCEPT_FUNCTION(gcvt);
INTERCEPT_FUNCTION(strcat); // NOLINT