summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-03-28 09:02:57 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-03-28 09:02:57 +0000
commit2e972f63b5fbd50109fe87d922afb58934c197dc (patch)
tree255656b6090bfed072597d786dd0f67816759528
parent3b56b9cf90a9ff38184f43acbbe5ca2412312dfc (diff)
downloadbcm5719-llvm-2e972f63b5fbd50109fe87d922afb58934c197dc.tar.gz
bcm5719-llvm-2e972f63b5fbd50109fe87d922afb58934c197dc.zip
[sanitizer] Intercept mktime.
llvm-svn: 204994
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc17
-rw-r--r--compiler-rt/test/msan/mktime.cc26
2 files changed, 42 insertions, 1 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 80b6a87bcac..91d0e77dc90 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -567,6 +567,20 @@ INTERCEPTOR(char *, asctime_r, __sanitizer_tm *tm, char *result) {
}
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, __sanitizer_tm *tm, char *result) {
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
diff --git a/compiler-rt/test/msan/mktime.cc b/compiler-rt/test/msan/mktime.cc
new file mode 100644
index 00000000000..d347ee3c133
--- /dev/null
+++ b/compiler-rt/test/msan/mktime.cc
@@ -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;
+}
OpenPOWER on IntegriCloud