From: Timo Sirainen Date: Thu, 19 Oct 2017 10:05:41 +0000 (+0300) Subject: lib: printf_format_fix*() - Support '*' in precision X-Git-Tag: 2.2.34~163 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b384d4cd92232fbd593e00e1388d9c0ee990b7b2;p=thirdparty%2Fdovecot%2Fcore.git lib: printf_format_fix*() - Support '*' in precision We're commonly using "%.*s" --- diff --git a/src/lib/printf-format-fix.c b/src/lib/printf-format-fix.c index bea65b1759..69539875c3 100644 --- a/src/lib/printf-format-fix.c +++ b/src/lib/printf-format-fix.c @@ -111,16 +111,10 @@ printf_format_fix_noalloc(const char *format, size_t *len_r) /* 3) Optional precision */ if (*p == '.') { - /* We don't bother supporting anything but numbers - here. 9999 should be long enough precision. */ - unsigned int i = 0; p++; - while (*p >= '0' && *p <= '9') { - if (++i > 4) { - i_panic("Too large precision starting at #%u in '%s'", - start_pos, format); - } - p++; + if (!verify_length(&p)) { + i_panic("Too large precision starting at #%u in '%s'", + start_pos, format); } } diff --git a/src/lib/test-printf-format-fix.c b/src/lib/test-printf-format-fix.c index 6c01541792..85f9b7a03c 100644 --- a/src/lib/test-printf-format-fix.c +++ b/src/lib/test-printf-format-fix.c @@ -21,8 +21,10 @@ static void test_unchanged() "Allow %#0- +s flags", "duplicate flags in different args %0-123s %0-123s", "Minimum length %9999s", + "Minimum length parameter %*s", "Precision %.9999s", "Precision %1.9999s", + "Precision parameter %1.*s %.*s", "Length modifiers %hd %hhd %ld %lld %Lg %jd %zd %td", "Specifiers %s %u %d %c %i %x %X %p %o %e %E %f %F %g %G %a %A", "%%doesn't cause confusion in %%m and %%n", @@ -119,7 +121,6 @@ enum fatal_test_state fatal_printf_format_fix(unsigned int stage) "Precision can't be too long %.10000s", "Precision can't be too long %1.10000s", "Precision doesn't support %1.-1s", - "Precision doesn't support %1.*s", }; if(stage >= N_ELEMENTS(fatals)) {