[compiler-rt] r185340 - [msan] Intercept stpcpy.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jul 1 08:19:37 PDT 2013


Author: eugenis
Date: Mon Jul  1 10:19:37 2013
New Revision: 185340

URL: http://llvm.org/viewvc/llvm-project?rev=185340&view=rev
Log:
[msan] Intercept stpcpy.

Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/msan/tests/msan_test.cc

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=185340&r1=185339&r2=185340&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Mon Jul  1 10:19:37 2013
@@ -167,6 +167,14 @@ INTERCEPTOR(char *, strncpy, char *dest,
   return res;
 }
 
+INTERCEPTOR(char *, stpcpy, char *dest, const char *src) {  // NOLINT
+  ENSURE_MSAN_INITED();
+  SIZE_T n = REAL(strlen)(src);
+  char *res = REAL(stpcpy)(dest, src);  // NOLINT
+  __msan_copy_poison(dest, src, n + 1);
+  return res;
+}
+
 INTERCEPTOR(char *, strdup, char *src) {
   ENSURE_MSAN_INITED();
   SIZE_T n = REAL(strlen)(src);
@@ -1135,6 +1143,7 @@ void InitializeInterceptors() {
   INTERCEPT_FUNCTION(wmemcpy);
   INTERCEPT_FUNCTION(wmemmove);
   INTERCEPT_FUNCTION(strcpy);  // NOLINT
+  INTERCEPT_FUNCTION(stpcpy);  // NOLINT
   INTERCEPT_FUNCTION(strdup);
   INTERCEPT_FUNCTION(__strdup);
   INTERCEPT_FUNCTION(strndup);

Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=185340&r1=185339&r2=185340&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Mon Jul  1 10:19:37 2013
@@ -1033,6 +1033,19 @@ TEST(MemorySanitizer, strncpy) {  // NOL
   EXPECT_POISONED(y[2]);
 }
 
+TEST(MemorySanitizer, stpcpy) {  // NOLINT
+  char* x = new char[3];
+  char* y = new char[3];
+  x[0] = 'a';
+  x[1] = *GetPoisoned<char>(1, 1);
+  x[2] = 0;
+  char *res = stpcpy(y, x);  // NOLINT
+  ASSERT_EQ(res, y + 2);
+  EXPECT_NOT_POISONED(y[0]);
+  EXPECT_POISONED(y[1]);
+  EXPECT_NOT_POISONED(y[2]);
+}
+
 TEST(MemorySanitizer, strtol) {
   char *e;
   assert(1 == strtol("1", &e, 10));





More information about the llvm-commits mailing list