[compiler-rt] r215106 - [msan] Fix fcvt interceptor.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Aug 7 05:45:56 PDT 2014


Author: eugenis
Date: Thu Aug  7 07:45:55 2014
New Revision: 215106

URL: http://llvm.org/viewvc/llvm-project?rev=215106&view=rev
Log:
[msan] Fix fcvt interceptor.

fcvt() result can be heap-allocated and must be unpoisoned.

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=215106&r1=215105&r2=215106&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Aug  7 07:45:55 2014
@@ -577,6 +577,7 @@ INTERCEPTOR(char *, fcvt, double x, int
   if (!__msan_has_dynamic_component()) {
     __msan_unpoison(b, sizeof(*b));
     __msan_unpoison(c, sizeof(*c));
+    if (res) __msan_unpoison(res, REAL(strlen)(res) + 1);
   }
   return res;
 }

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=215106&r1=215105&r2=215106&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Aug  7 07:45:55 2014
@@ -2064,8 +2064,26 @@ TEST(MemorySanitizer, fcvt) {
   char *str = fcvt(12345.6789, 10, &a, &b);
   EXPECT_NOT_POISONED(a);
   EXPECT_NOT_POISONED(b);
+  ASSERT_NE(nullptr, str);
+  EXPECT_NOT_POISONED(str[0]);
+  ASSERT_NE(0U, strlen(str));
 }
 
+TEST(MemorySanitizer, fcvt_long) {
+  int a, b;
+  break_optimization(&a);
+  break_optimization(&b);
+  EXPECT_POISONED(a);
+  EXPECT_POISONED(b);
+  char *str = fcvt(111111112345.6789, 10, &a, &b);
+  EXPECT_NOT_POISONED(a);
+  EXPECT_NOT_POISONED(b);
+  ASSERT_NE(nullptr, str);
+  EXPECT_NOT_POISONED(str[0]);
+  ASSERT_NE(0U, strlen(str));
+}
+
+
 TEST(MemorySanitizer, memchr) {
   char x[10];
   break_optimization(x);





More information about the llvm-commits mailing list