diff options
author | Alexander Potapenko <glider@google.com> | 2013-04-10 15:13:00 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2013-04-10 15:13:00 +0000 |
commit | 227e22de5a72bcbb619f384fc9f1a426f897aea1 (patch) | |
tree | bc5d7173dbf8f469d61ef93190648ad57fd7a322 | |
parent | 6bebee0d5c5b31107d818d783f51b5a6f6e01295 (diff) | |
download | bcm5719-llvm-227e22de5a72bcbb619f384fc9f1a426f897aea1.tar.gz bcm5719-llvm-227e22de5a72bcbb619f384fc9f1a426f897aea1.zip |
[ASan] Do not check the shadow of NULL argument in the time() interceptor.
Add a test for time().
llvm-svn: 179177
-rw-r--r-- | compiler-rt/lib/asan/lit_tests/time_interceptor.cc | 20 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler-rt/lib/asan/lit_tests/time_interceptor.cc b/compiler-rt/lib/asan/lit_tests/time_interceptor.cc new file mode 100644 index 00000000000..bade7bbc687 --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/time_interceptor.cc @@ -0,0 +1,20 @@ +// RUN: %clangxx_asan -m64 -O0 %s -fsanitize-address-zero-base-shadow -pie -o %t && %t 2>&1 | %symbolize | FileCheck %s + +// Test the time() interceptor. Also includes a regression test for time(NULL), +// which caused ASan to crash in the zero-based shadow mode. + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +int main() { + time_t *tm = (time_t*)malloc(sizeof(time_t)); + free(tm); + time_t t = time(NULL); + fprintf(stderr, "Time: %s\n", ctime(&t)); + // CHECK: {{Time: .* .* .*}} + t = time(tm); + printf("Time: %s\n", ctime(&t)); + // CHECK: use-after-free + return 0; +} diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 18ff952dfa1..43e5a6df355 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -236,7 +236,7 @@ INTERCEPTOR(unsigned long, time, unsigned long *t) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, time, t); unsigned long res = REAL(time)(t); - if (res != (unsigned long)-1) { + if (t && res != (unsigned long)-1) { COMMON_INTERCEPTOR_WRITE_RANGE(ctx, t, sizeof(*t)); } return res; |