Skip to contentSkip to conversation

Reject malformed printf specifications with digits after '*'

PATCH In review Gioele Barabucci 2 participants 2 messages Dec 6, 2015 – Jun 6, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Reject malformed printf specifications with digits after '*'

Hello,

I am forwarding a patch related to the bug described at
<https://bugs.debian.org/779618>.

You can find the same patch at
<https://github.com/gioele/dash/commit/ebdd2d7992c4b2bf49d9af2eed33e3c18c86dfc6>.

I refreshed the patch to be compatible with the current code, but left the original author as the git author. I hope this is fine.

Regards,

--
Gioele Barabucci <[email protected]>

From ebdd2d7992c4b2bf49d9af2eed33e3c18c86dfc6 Mon Sep 17 00:00:00 2001
From: Patrick Brown <[email protected]>
Date: Mon, 2 Mar 2015 23:10:09 -0500
Subject: [PATCH] [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
---
 src/bltin/printf.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
src/bltin/printf.c +1 -7
index 9673e10..83077a7 100644
@@ -175,17 +175,20 @@ pc:
 
 			/* skip to field width */
 			fmt += strspn(fmt, SKIP1);
-			if (*fmt == '*')
+			if (*fmt == '*') {
 				*param++ = getuintmax(1);
-
-			/* skip to possible '.', get following precision */
-			fmt += strspn(fmt, SKIP2);
-			if (*fmt == '.')
 				++fmt;
-			if (*fmt == '*')
-				*param++ = getuintmax(1);
#1 lore raw

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

Quoted 10 lines · Gioele Barabucci

Hello,

I am forwarding a patch related to the bug described at
<https://bugs.debian.org/779618>.

You can find the same patch at
<https://github.com/gioele/dash/commit/ebdd2d7992c4b2bf49d9af2eed33e3c18c86dfc6>.

I refreshed the patch to be compatible with the current code, but left the original author as the git author. I hope this is fine.

Patch applied with formatting fix-ups.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt