dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gioele Barabucci <gioele@svario.it>
To: dash@vger.kernel.org
Subject: [PATCH] [BUILTIN] Reject malformed printf specifications with digits after '*'
Date: Sun, 6 Dec 2015 15:09:42 +0100	[thread overview]
Message-ID: <n41fj7$tj9$1@ger.gmane.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

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 <gioele@svario.it>




[-- Attachment #2: 0001-BUILTIN-Reject-malformed-printf-specifications-with-.patch --]
[-- Type: text/x-patch, Size: 1581 bytes --]

From ebdd2d7992c4b2bf49d9af2eed33e3c18c86dfc6 Mon Sep 17 00:00:00 2001
From: Patrick Brown <opensource@whoopdedo.org>
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

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

Originally-by: Patrick Brown <opensource@whoopdedo.org>
Forwarded-by: Gioele Barabucci <gioele@svario.it>
---
 src/bltin/printf.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index 9673e10..83077a7 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -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);

             reply	other threads:[~2015-12-06 14:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-06 14:09 Gioele Barabucci [this message]
2016-06-06 10:41 ` builtin: Reject malformed printf specifications with digits after '*' Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='n41fj7$tj9$1@ger.gmane.org' \
    --to=gioele@svario.it \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).