dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: "Vladimir N. Oleynik" <dzo@simtreas.ru>
Cc: dash@vger.kernel.org
Subject: [PATCH] parser: Fix regression on ${#10} expansion
Date: Mon, 8 Feb 2021 14:41:28 +1100	[thread overview]
Message-ID: <20210208034127.GA31149@gondor.apana.org.au> (raw)
In-Reply-To: <b91eab68-0a8a-36f0-a947-344cf2c168f5@simtreas.ru>

Thanks for the patch!

---8<---
Vladimir N. Oleynik <dzo@simtreas.ru> wrote:
> 
> dash have bug for ${#10} and etc: ignores 0... in name (without errors :)
> 
> $ foo() { echo "length 10-th arg '${10}' is ${#10}"; }
> $ foo a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
> length 10-th arg 'a10' is 2
> 
> But need:
> length 10-th arg 'a10' is 3
> 
> Micro patch attached
>
> --- parser.c~   2021-02-04 00:51:34.000000000 +0400
> +++ parser.c    2021-02-05 12:42:43.616635640 +0400
> @@ -1274,7 +1274,7 @@
>                        do {
>                                STPUTC(c, out);
>                                c = pgetc_eatbnl();
> -                       } while (!subtype && is_digit(c));
> +                       } while ((!subtype || subtype == VSLENGTH) && is_digit(c));
>                } else if (c != '}') {
>                        int cc = c;

I would rather test against VSNORMAL.

Fixes: 7710a926b321 ("parser: Only accept single-digit parameter...")
Reported-by: Vladimir N. Oleynik <dzo@simtreas.ru>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/src/parser.c b/src/parser.c
index 3c80d17..834d2e3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1252,7 +1252,7 @@ varname:
 			do {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
-			} while (!subtype && is_digit(c));
+			} while (subtype != VSNORMAL && is_digit(c));
 		} else if (c != '}') {
 			int cc = c;
 
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2021-02-08  3:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  8:49 [PATCH] [BUG] ${#10} Vladimir N. Oleynik
2021-02-08  3:41 ` Herbert Xu [this message]
2021-02-10 15:30   ` [PATCH] parser: Fix regression on ${#10} expansion Vladimir N. Oleynik
2021-02-11  4:55     ` 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=20210208034127.GA31149@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dash@vger.kernel.org \
    --cc=dzo@simtreas.ru \
    --subject='Re: [PATCH] parser: Fix regression on ${#10} expansion' \
    /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

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).