[compiler-rt] r199899 - [Sanitizer] Fix false positive in snprintf interceptor - take the number of actually written symbols from real snprintf call.

Alexey Samsonov samsonov at google.com
Thu Jan 23 07:09:38 PST 2014


Author: samsonov
Date: Thu Jan 23 09:09:38 2014
New Revision: 199899

URL: http://llvm.org/viewvc/llvm-project?rev=199899&view=rev
Log:
[Sanitizer] Fix false positive in snprintf interceptor - take the number of actually written symbols from real snprintf call.

Modified:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/printf-1.c
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/printf-1.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/printf-1.c?rev=199899&r1=199898&r2=199899&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/printf-1.c (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/printf-1.c Thu Jan 23 09:09:38 2014
@@ -9,8 +9,13 @@ int main() {
   volatile int x = 12;
   volatile float f = 1.239;
   volatile char s[] = "34";
-  printf("%c %d %.3f %s\n", c, x, f, s);
-  return 0;
   // Check that printf works fine under Asan.
+  printf("%c %d %.3f %s\n", c, x, f, s);
   // CHECK: 0 12 1.239 34
+  // Check that snprintf works fine under Asan.
+  char buf[4];
+  snprintf(buf, 1000, "qwe");
+  printf("%s\n", buf);
+  // CHECK: qwe
+  return 0;
 }

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=199899&r1=199898&r2=199899&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Jan 23 09:09:38 2014
@@ -706,10 +706,12 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_sscanf,
   {                                                                            \
     VPRINTF_INTERCEPTOR_ENTER(vname, str, size, __VA_ARGS__)                   \
     if (common_flags()->check_printf) {                                        \
-      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, str, size);                          \
       printf_common(ctx, format, aq);                                          \
     }                                                                          \
     int res = REAL(vname)(str, size, __VA_ARGS__);                             \
+    if (res >= 0 && common_flags()->check_printf) {                            \
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, str, Min(size, (SIZE_T)(res + 1)));  \
+    }                                                                          \
     VPRINTF_INTERCEPTOR_RETURN();                                              \
     return res;                                                                \
   }





More information about the llvm-commits mailing list