[compiler-rt] r316613 - [msan] Intercept __strxfrm_l.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 25 14:40:17 PDT 2017
Author: eugenis
Date: Wed Oct 25 14:40:17 2017
New Revision: 316613
URL: http://llvm.org/viewvc/llvm-project?rev=316613&view=rev
Log:
[msan] Intercept __strxfrm_l.
Added:
compiler-rt/trunk/test/msan/__strxfrm_l.cc
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/test/msan/strxfrm.cc
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=316613&r1=316612&r2=316613&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Wed Oct 25 14:40:17 2017
@@ -457,6 +457,20 @@ INTERCEPTOR(SIZE_T, strxfrm_l, char *des
return res;
}
+#if SANITIZER_LINUX
+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 MSAN_MAYBE_INTERCEPT___STRXFRM_L INTERCEPT_FUNCTION(__strxfrm_l)
+#else
+#define MSAN_MAYBE_INTERCEPT___STRXFRM_L
+#endif
+
#define INTERCEPTOR_STRFTIME_BODY(char_type, ret_type, func, s, ...) \
ENSURE_MSAN_INITED(); \
ret_type res = REAL(func)(s, __VA_ARGS__); \
@@ -1521,6 +1535,7 @@ void InitializeInterceptors() {
#endif
INTERCEPT_FUNCTION(strxfrm);
INTERCEPT_FUNCTION(strxfrm_l);
+ MSAN_MAYBE_INTERCEPT___STRXFRM_L;
INTERCEPT_FUNCTION(strftime);
INTERCEPT_FUNCTION(strftime_l);
MSAN_MAYBE_INTERCEPT___STRFTIME_L;
Added: compiler-rt/trunk/test/msan/__strxfrm_l.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/__strxfrm_l.cc?rev=316613&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/__strxfrm_l.cc (added)
+++ compiler-rt/trunk/test/msan/__strxfrm_l.cc Wed Oct 25 14:40:17 2017
@@ -0,0 +1,19 @@
+// RUN: %clangxx_msan -std=c++11 -O0 -g %s -o %t && %run %t
+// REQUIRES: x86_64-linux
+
+#include <assert.h>
+#include <locale.h>
+#include <sanitizer/msan_interface.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern "C" decltype(strxfrm_l) __strxfrm_l;
+
+int main(void) {
+ char q[10];
+ locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0);
+ size_t n = __strxfrm_l(q, "qwerty", sizeof(q), loc);
+ assert(n < sizeof(q));
+ __msan_check_mem_is_initialized(q, n + 1);
+ return 0;
+}
Modified: compiler-rt/trunk/test/msan/strxfrm.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/strxfrm.cc?rev=316613&r1=316612&r2=316613&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/strxfrm.cc (original)
+++ compiler-rt/trunk/test/msan/strxfrm.cc Wed Oct 25 14:40:17 2017
@@ -1,14 +1,21 @@
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
#include <assert.h>
+#include <locale.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));
+ size_t n = strxfrm(q, "abcdef", sizeof(q));
+ assert(n < sizeof(q));
+ __msan_check_mem_is_initialized(q, n + 1);
+
+ locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0);
+
+ __msan_poison(&q, sizeof(q));
+ n = strxfrm_l(q, "qwerty", sizeof(q), loc);
assert(n < sizeof(q));
__msan_check_mem_is_initialized(q, n + 1);
return 0;
More information about the llvm-commits
mailing list