[compiler-rt] r204994 - [sanitizer] Intercept mktime.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Mar 28 02:02:58 PDT 2014
Author: eugenis
Date: Fri Mar 28 04:02:57 2014
New Revision: 204994
URL: http://llvm.org/viewvc/llvm-project?rev=204994&view=rev
Log:
[sanitizer] Intercept mktime.
Added:
compiler-rt/trunk/test/msan/mktime.cc (with props)
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=204994&r1=204993&r2=204994&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Mar 28 04:02:57 2014
@@ -567,6 +567,20 @@ INTERCEPTOR(char *, asctime_r, __sanitiz
}
return res;
}
+INTERCEPTOR(long, mktime, __sanitizer_tm *tm) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, mktime, tm);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_sec, sizeof(tm->tm_sec));
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_min, sizeof(tm->tm_min));
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_hour, sizeof(tm->tm_hour));
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_mday, sizeof(tm->tm_mday));
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_mon, sizeof(tm->tm_mon));
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_year, sizeof(tm->tm_year));
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &tm->tm_isdst, sizeof(tm->tm_isdst));
+ long res = REAL(mktime)(tm);
+ if (res != -1) unpoison_tm(ctx, tm);
+ return res;
+}
#define INIT_LOCALTIME_AND_FRIENDS \
COMMON_INTERCEPT_FUNCTION(localtime); \
COMMON_INTERCEPT_FUNCTION(localtime_r); \
@@ -575,7 +589,8 @@ INTERCEPTOR(char *, asctime_r, __sanitiz
COMMON_INTERCEPT_FUNCTION(ctime); \
COMMON_INTERCEPT_FUNCTION(ctime_r); \
COMMON_INTERCEPT_FUNCTION(asctime); \
- COMMON_INTERCEPT_FUNCTION(asctime_r);
+ COMMON_INTERCEPT_FUNCTION(asctime_r); \
+ COMMON_INTERCEPT_FUNCTION(mktime);
#else
#define INIT_LOCALTIME_AND_FRIENDS
#endif // SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS
Added: compiler-rt/trunk/test/msan/mktime.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/mktime.cc?rev=204994&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/mktime.cc (added)
+++ compiler-rt/trunk/test/msan/mktime.cc Fri Mar 28 04:02:57 2014
@@ -0,0 +1,26 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O0 -g -DUNINIT %s -o %t && not %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <time.h>
+
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+ struct tm tm;
+ tm.tm_year = 2014;
+ tm.tm_mon = 3;
+ tm.tm_mday = 28;
+#ifndef UNINIT
+ tm.tm_hour = 13;
+#endif
+ tm.tm_min = 4;
+ tm.tm_sec = 42;
+ tm.tm_isdst = -1;
+ time_t t = mktime(&tm);
+ // CHECK: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: in main{{.*}}mktime.cc:[[@LINE-2]]
+ assert(t != -1);
+ assert(__msan_test_shadow(&tm, sizeof(tm)) == -1);
+ return 0;
+}
Propchange: compiler-rt/trunk/test/msan/mktime.cc
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the llvm-commits
mailing list