[compiler-rt] r206179 - [msan] Intercept wcsftime().
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Mon Apr 14 07:59:42 PDT 2014
Author: eugenis
Date: Mon Apr 14 09:59:42 2014
New Revision: 206179
URL: http://llvm.org/viewvc/llvm-project?rev=206179&view=rev
Log:
[msan] Intercept wcsftime().
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/tests/msan_test.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=206179&r1=206178&r2=206179&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Mon Apr 14 09:59:42 2014
@@ -453,13 +453,43 @@ INTERCEPTOR(int, swprintf, void *str, up
return res;
}
-// SIZE_T strftime(char *s, SIZE_T max, const char *format,const struct tm *tm);
+#define INTERCEPTOR_STRFTIME_BODY(char_type, ret_type, func, s, ...) \
+ ENSURE_MSAN_INITED(); \
+ ret_type res = REAL(func)(s, __VA_ARGS__); \
+ if (s) __msan_unpoison(s, sizeof(char_type) * (res + 1)); \
+ return res;
+
INTERCEPTOR(SIZE_T, strftime, char *s, SIZE_T max, const char *format,
__sanitizer_tm *tm) {
- ENSURE_MSAN_INITED();
- SIZE_T res = REAL(strftime)(s, max, format, tm);
- if (res) __msan_unpoison(s, res + 1);
- return res;
+ INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime, s, max, format, tm);
+}
+
+INTERCEPTOR(SIZE_T, strftime_l, char *s, SIZE_T max, const char *format,
+ __sanitizer_tm *tm, void *loc) {
+ INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime_l, s, max, format, tm, loc);
+}
+
+INTERCEPTOR(SIZE_T, __strftime_l, char *s, SIZE_T max, const char *format,
+ __sanitizer_tm *tm, void *loc) {
+ INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, __strftime_l, s, max, format, tm,
+ loc);
+}
+
+INTERCEPTOR(SIZE_T, wcsftime, wchar_t *s, SIZE_T max, const wchar_t *format,
+ __sanitizer_tm *tm) {
+ INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, wcsftime, s, max, format, tm);
+}
+
+INTERCEPTOR(SIZE_T, wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format,
+ __sanitizer_tm *tm, void *loc) {
+ INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, wcsftime_l, s, max, format, tm,
+ loc);
+}
+
+INTERCEPTOR(SIZE_T, __wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format,
+ __sanitizer_tm *tm, void *loc) {
+ INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, __wcsftime_l, s, max, format, tm,
+ loc);
}
INTERCEPTOR(int, mbtowc, wchar_t *dest, const char *src, SIZE_T n) {
@@ -1518,6 +1548,11 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(snprintf);
INTERCEPT_FUNCTION(swprintf);
INTERCEPT_FUNCTION(strftime);
+ INTERCEPT_FUNCTION(strftime_l);
+ INTERCEPT_FUNCTION(__strftime_l);
+ INTERCEPT_FUNCTION(wcsftime);
+ INTERCEPT_FUNCTION(wcsftime_l);
+ INTERCEPT_FUNCTION(__wcsftime_l);
INTERCEPT_FUNCTION(mbtowc);
INTERCEPT_FUNCTION(mbrtowc);
INTERCEPT_FUNCTION(wcslen);
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=206179&r1=206178&r2=206179&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Mon Apr 14 09:59:42 2014
@@ -1859,6 +1859,17 @@ TEST(MemorySanitizer, mbrtowc) {
EXPECT_NOT_POISONED(wx);
}
+TEST(MemorySanitizer, wcsftime) {
+ wchar_t x[100];
+ time_t t = time(NULL);
+ struct tm tms;
+ struct tm *tmres = localtime_r(&t, &tms);
+ ASSERT_NE((void *)0, tmres);
+ size_t res = wcsftime(x, sizeof(x) / sizeof(x[0]), L"%Y-%m-%d", tmres);
+ EXPECT_GT(res, 0UL);
+ EXPECT_EQ(res, wcslen(x));
+}
+
TEST(MemorySanitizer, gettimeofday) {
struct timeval tv;
struct timezone tz;
More information about the llvm-commits
mailing list