[compiler-rt] r205001 - [sanitizer] Intercept rand_r.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Mar 28 04:21:45 PDT 2014
Author: eugenis
Date: Fri Mar 28 06:21:45 2014
New Revision: 205001
URL: http://llvm.org/viewvc/llvm-project?rev=205001&view=rev
Log:
[sanitizer] Intercept rand_r.
Added:
compiler-rt/trunk/test/msan/rand_r.cc (with props)
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
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=205001&r1=205000&r2=205001&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 06:21:45 2014
@@ -3232,6 +3232,18 @@ INTERCEPTOR(int, lrand48_r, void *buffer
#define INIT_DRAND48_R
#endif
+#if SANITIZER_INTERCEPT_RAND_R
+INTERCEPTOR(int, rand_r, unsigned *seedp) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, rand_r, seedp);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, seedp, sizeof(*seedp));
+ return REAL(rand_r)(seedp);
+}
+#define INIT_RAND_R COMMON_INTERCEPT_FUNCTION(rand_r);
+#else
+#define INIT_RAND_R
+#endif
+
#if SANITIZER_INTERCEPT_GETLINE
INTERCEPTOR(SSIZE_T, getline, char **lineptr, SIZE_T *n, void *stream) {
void *ctx;
@@ -3704,6 +3716,7 @@ INTERCEPTOR(int, ftime, __sanitizer_time
INIT_LGAMMA; \
INIT_LGAMMA_R; \
INIT_DRAND48_R; \
+ INIT_RAND_R; \
INIT_GETLINE; \
INIT_ICONV; \
INIT_TIMES; \
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=205001&r1=205000&r2=205001&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Mar 28 06:21:45 2014
@@ -169,6 +169,7 @@
#define SANITIZER_INTERCEPT_LGAMMA SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_LGAMMA_R SI_LINUX
#define SANITIZER_INTERCEPT_DRAND48_R SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_RAND_R SI_MAC || SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_ICONV SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_TIMES SI_NOT_WINDOWS
Added: compiler-rt/trunk/test/msan/rand_r.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/rand_r.cc?rev=205001&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/rand_r.cc (added)
+++ compiler-rt/trunk/test/msan/rand_r.cc Fri Mar 28 06:21:45 2014
@@ -0,0 +1,18 @@
+// 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 <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ unsigned seed;
+#ifndef UNINIT
+ seed = 42;
+#endif
+ int v = rand_r(&seed);
+ // CHECK: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: in main{{.*}}rand_r.cc:[[@LINE-2]]
+ if (v) printf(".\n");
+ return 0;
+}
Propchange: compiler-rt/trunk/test/msan/rand_r.cc
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the llvm-commits
mailing list