diff options
| -rw-r--r-- | compiler-rt/lib/msan/tests/msan_test.cc | 7 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc | 5 | 
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc index 0716460dcd2..4d6ad7da3a4 100644 --- a/compiler-rt/lib/msan/tests/msan_test.cc +++ b/compiler-rt/lib/msan/tests/msan_test.cc @@ -1397,6 +1397,13 @@ TEST(MemorySanitizer, getitimer) {    assert(!res);  } +TEST(MemorySanitizer, setitimer_null) { +  setitimer(ITIMER_VIRTUAL, 0, 0); +  // Not testing the return value, since it the behaviour seems to differ +  // between libc implementations and POSIX. +  // Should never crash, though. +} +  TEST(MemorySanitizer, time) {    time_t t;    EXPECT_POISONED(t); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 5a7d77c3b51..bf99141788b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -758,7 +758,7 @@ INTERCEPTOR(int, getitimer, int which, void *curr_value) {    void *ctx;    COMMON_INTERCEPTOR_ENTER(ctx, getitimer, which, curr_value);    int res = REAL(getitimer)(which, curr_value); -  if (!res) { +  if (!res && curr_value) {      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, curr_value, struct_itimerval_sz);    }    return res; @@ -766,7 +766,8 @@ INTERCEPTOR(int, getitimer, int which, void *curr_value) {  INTERCEPTOR(int, setitimer, int which, const void *new_value, void *old_value) {    void *ctx;    COMMON_INTERCEPTOR_ENTER(ctx, setitimer, which, new_value, old_value); -  COMMON_INTERCEPTOR_READ_RANGE(ctx, new_value, struct_itimerval_sz); +  if (new_value) +    COMMON_INTERCEPTOR_READ_RANGE(ctx, new_value, struct_itimerval_sz);    int res = REAL(setitimer)(which, new_value, old_value);    if (!res && old_value) {      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, old_value, struct_itimerval_sz);  | 

