]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: printf_format_fix*() - Support '*' in precision
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 19 Oct 2017 10:05:41 +0000 (13:05 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Thu, 19 Oct 2017 15:13:07 +0000 (18:13 +0300)
We're commonly using "%.*s"

src/lib/printf-format-fix.c
src/lib/test-printf-format-fix.c

index 153d30612f9b4c9e71f0cda72f9f8fbad4dfa90f..096c45ab3c72312cc256a2f7c88ec477479fa776 100644 (file)
@@ -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);
                        }
                }
 
index 9409ea59ee9c07017330fd14748a03887a8bceaf..fa63da3dbc4b4f9730a6cb3e46882be6826c1c2e 100644 (file)
@@ -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)) {