Skip to content
Snippets Groups Projects
Commit 0134f725 authored by Patrick Brown's avatar Patrick Brown Committed by Herbert Xu
Browse files

builtin: Reject malformed printf specifications with digits after '*'

Dash doesn't notice when a format string has digits following a * width
specifier.

    $ dash -c 'printf "%*0s  " 1 2 && echo FAIL || echo OK'
    %10s  FAIL

    $ bash -c 'printf "%*0s  " 1 2 && echo FAIL || echo OK'
    bash: line 0: printf: `0': invalid format character
    OK
    $ mksh -c 'printf "%*0s  " 1 2 && echo FAIL || echo OK'
    printf: %*0: invalid conversion specification
    OK

With this patch dash complains about the malformed specifications.

    $ ./src/dash -c 'printf "%*0s  " 1 2 && echo FAIL || echo OK'
    ./src/dash: 1: printf: %*0: invalid directive
    OK

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779618



Originally-by: default avatarPatrick Brown <opensource@whoopdedo.org>
Forwarded-by: default avatarGioele Barabucci <gioele@svario.it>

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 801fbd56
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -175,17 +175,24 @@ pc:
 
/* skip to field width */
fmt += strspn(fmt, SKIP1);
if (*fmt == '*')
*param++ = getuintmax(1);
/* skip to possible '.', get following precision */
fmt += strspn(fmt, SKIP2);
if (*fmt == '.')
if (*fmt == '*') {
++fmt;
if (*fmt == '*')
*param++ = getuintmax(1);
} else {
/* skip to possible '.',
* get following precision
*/
fmt += strspn(fmt, SKIP2);
}
 
fmt += strspn(fmt, SKIP2);
if (*fmt == '.') {
++fmt;
if (*fmt == '*') {
++fmt;
*param++ = getuintmax(1);
} else
fmt += strspn(fmt, SKIP2);
}
 
ch = *fmt;
if (!ch)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment