[compiler-rt] r317494 - [Sanitizers] Check pthread_setcancel{state|type} interceptor arguments for != nullptr.

Alex Shlyapnikov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 09:43:29 PST 2017


Author: alekseyshl
Date: Mon Nov  6 09:43:28 2017
New Revision: 317494

URL: http://llvm.org/viewvc/llvm-project?rev=317494&view=rev
Log:
[Sanitizers] Check pthread_setcancel{state|type} interceptor arguments for != nullptr.

Summary:
According to man, pthread_setcancelstate's oldstate and
pthread_setcanceltype's oldtype parameters can be nullptr.
Check these parameters for != nullptr before attempting to
access their shadow memory.

Reviewers: dvyukov

Subscribers: kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D39626

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=317494&r1=317493&r2=317494&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Nov  6 09:43:28 2017
@@ -5835,7 +5835,7 @@ INTERCEPTOR(int, pthread_setcancelstate,
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, pthread_setcancelstate, state, oldstate);
   int res = REAL(pthread_setcancelstate)(state, oldstate);
-  if (res == 0)
+  if (res == 0 && oldstate != nullptr)
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, oldstate, sizeof(*oldstate));
   return res;
 }
@@ -5844,7 +5844,7 @@ INTERCEPTOR(int, pthread_setcanceltype,
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, pthread_setcanceltype, type, oldtype);
   int res = REAL(pthread_setcanceltype)(type, oldtype);
-  if (res == 0)
+  if (res == 0 && oldtype != nullptr)
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, oldtype, sizeof(*oldtype));
   return res;
 }




More information about the llvm-commits mailing list