summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/lib/msan/msan_interceptors.cc19
-rw-r--r--compiler-rt/test/msan/strxfrm.cc15
2 files changed, 34 insertions, 0 deletions
diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc
index 17331ee8256..7162ba73562 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cc
+++ b/compiler-rt/lib/msan/msan_interceptors.cc
@@ -397,6 +397,23 @@ INTERCEPTOR(int, swprintf, void *str, uptr size, void *format, ...) {
return res;
}
+INTERCEPTOR(SIZE_T, strxfrm, char *dest, const char *src, SIZE_T n) {
+ ENSURE_MSAN_INITED();
+ CHECK_UNPOISONED(src, REAL(strlen)(src) + 1);
+ SIZE_T res = REAL(strxfrm)(dest, src, n);
+ if (res < n) __msan_unpoison(dest, res + 1);
+ return res;
+}
+
+INTERCEPTOR(SIZE_T, strxfrm_l, char *dest, const char *src, SIZE_T n,
+ void *loc) {
+ ENSURE_MSAN_INITED();
+ CHECK_UNPOISONED(src, REAL(strlen)(src) + 1);
+ SIZE_T res = REAL(strxfrm_l)(dest, src, n, loc);
+ if (res < n) __msan_unpoison(dest, res + 1);
+ return res;
+}
+
#define INTERCEPTOR_STRFTIME_BODY(char_type, ret_type, func, s, ...) \
ENSURE_MSAN_INITED(); \
ret_type res = REAL(func)(s, __VA_ARGS__); \
@@ -1497,6 +1514,8 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(strtoull_l);
INTERCEPT_FUNCTION(vswprintf);
INTERCEPT_FUNCTION(swprintf);
+ INTERCEPT_FUNCTION(strxfrm);
+ INTERCEPT_FUNCTION(strxfrm_l);
INTERCEPT_FUNCTION(strftime);
INTERCEPT_FUNCTION(strftime_l);
INTERCEPT_FUNCTION(__strftime_l);
diff --git a/compiler-rt/test/msan/strxfrm.cc b/compiler-rt/test/msan/strxfrm.cc
new file mode 100644
index 00000000000..b930a6af69c
--- /dev/null
+++ b/compiler-rt/test/msan/strxfrm.cc
@@ -0,0 +1,15 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t
+
+#include <assert.h>
+#include <sanitizer/msan_interface.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(void) {
+ const char *p = "abcdef";
+ char q[10];
+ size_t n = strxfrm(q, p, sizeof(q));
+ assert(n < sizeof(q));
+ __msan_check_mem_is_initialized(q, n + 1);
+ return 0;
+}
OpenPOWER on IntegriCloud