diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-01-25 11:43:32 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-01-25 11:43:32 +0000 |
commit | 4899fb5cfba666ebfe88c5b817f3b4436f108b25 (patch) | |
tree | aa141b7641474cb7418e6dc64f92943a6c5fe9f1 /compiler-rt | |
parent | e83aea35ba803c8b478749a9f57dd680ceceadbc (diff) | |
download | bcm5719-llvm-4899fb5cfba666ebfe88c5b817f3b4436f108b25.tar.gz bcm5719-llvm-4899fb5cfba666ebfe88c5b817f3b4436f108b25.zip |
[Sanitizer] fix errors in scanf interceptors: add support for %c and fix cases like %5d
llvm-svn: 173440
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc | 28 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc | 4 |
2 files changed, 24 insertions, 8 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc index 6da025cf937..72ff34a230f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_scanf.inc @@ -23,6 +23,7 @@ struct ScanfSpec { // One-letter specs. static const ScanfSpec scanf_specs[] = { + {'c', sizeof(char)}, {'p', sizeof(void *)}, {'e', sizeof(float)}, {'E', sizeof(float)}, @@ -96,16 +97,27 @@ static void scanf_common(void *ctx, const char *format, va_list ap_const) { 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') { diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc index 00b260479da..e8bd1954bde 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc @@ -65,6 +65,7 @@ TEST(SanitizerCommonInterceptors, Scanf) { 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 @@ TEST(SanitizerCommonInterceptors, Scanf) { 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); } |