[llvm-commits] [compiler-rt] r173440 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_common_interceptors_scanf.inc tests/sanitizer_scanf_interceptor_test.cc
Alexey Samsonov
samsonov at google.com
Fri Jan 25 03:43:33 PST 2013
Author: samsonov
Date: Fri Jan 25 05:43:32 2013
New Revision: 173440
URL: http://llvm.org/viewvc/llvm-project?rev=173440&view=rev
Log:
[Sanitizer] fix errors in scanf interceptors: add support for %c and fix cases like %5d
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc?rev=173440&r1=173439&r2=173440&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc Fri Jan 25 05:43:32 2013
@@ -23,6 +23,7 @@
// One-letter specs.
static const ScanfSpec scanf_specs[] = {
+ {'c', sizeof(char)},
{'p', sizeof(void *)},
{'e', sizeof(float)},
{'E', sizeof(float)},
@@ -96,16 +97,27 @@
continue;
}
++p;
- if (*p == '*' || *p == '%' || *p == 0) {
- ++p;
+ if (*p == '*' || *p == '%' || *p == '\0') {
+ if (*p != '\0')
+ ++p;
continue;
}
- if (*p == '0' || (*p >= '1' && *p <= '9')) {
- size = internal_atoll(p);
- // +1 for the \0 at the end
- COMMON_INTERCEPTOR_WRITE_RANGE(ctx, va_arg(aq, void *), size + 1);
- ++p;
- continue;
+
+ unsigned field_width = 0;
+ if (*p >= '0' && *p <= '9') {
+ field_width = internal_atoll(p);
+ while (*p >= '0' && *p <= '9')
+ p++;
+ }
+ if (field_width > 0) {
+ // +1 for the \0 at the end.
+ if (*p == 's')
+ field_width++;
+ if (*p == 's' || *p == 'c') {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, va_arg(aq, void*), field_width);
+ ++p;
+ continue;
+ }
}
if (*p == 'L' || *p == 'q') {
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc?rev=173440&r1=173439&r2=173440&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc Fri Jan 25 05:43:32 2013
@@ -65,6 +65,7 @@
testScanf("%ld", 1, L);
testScanf("%llu", 1, LL);
testScanf("a %hd%hhx", 2, S, C);
+ testScanf("%c", 1, C);
testScanf("%%", 0);
testScanf("a%%", 0);
@@ -79,7 +80,10 @@
testScanf("%nf", 1, I);
testScanf("%10s", 1, 11);
+ testScanf("%10c", 1, 10);
testScanf("%%10s", 0);
testScanf("%*10s", 0);
testScanf("%*d", 0);
+
+ testScanf("%4d%8f%c", 3, I, F, C);
}
More information about the llvm-commits
mailing list