Re: [v2 PATCH] expand: Escape minus sign in arithmetic expansion
On Tue, May 29, 2018 at 02:00:26AM +0800, Herbert Xu wrote: > On Mon, May 28, 2018 at 12:22:00AM +0800, Herbert Xu wrote: > > The minus sign generated from arithmetic expansion is currently > > unquoted which causes anomalies when the result is used in where > > the quoting matters. > > This patch fixes it by explicitly calling memtodest for the minus > > sign. > > Signed-off-by: Herbert Xu > This was buggy. Here is an update. > ---8<--- > The minus sign generated from arithmetic expansion is currently > unquoted which causes anomalies when the result is used in where > the quoting matters. > This patch fixes it by explicitly calling memtodest for the minus > sign. > Signed-off-by: Herbert Xu > diff --git a/src/expand.c b/src/expand.c > index 7a51766..7ed1bc0 100644 > --- a/src/expand.c > +++ b/src/expand.c > @@ -490,7 +490,14 @@ expari(int flag) > result = arith(p + 1); > popstackmark(); > > - len = cvtnum(result); > + len = 0; > + if (result < 0) { > + memtodest("-", 1, flag); > + result = -result; This negation overflows if result is INTMAX_MIN, leading to undefined behaviour. Perhaps leave the memtodest call but use STADJUST to remove the minus sign itself, leaving only the CTLESC or nothing. > + len++; > + } > + > + len += cvtnum(result); > > if (likely(!(flag & EXP_QUOTED))) > recordregion(begoff, begoff + len, 0); -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[v2 PATCH] expand: Escape minus sign in arithmetic expansion
On Mon, May 28, 2018 at 12:22:00AM +0800, Herbert Xu wrote: > The minus sign generated from arithmetic expansion is currently > unquoted which causes anomalies when the result is used in where > the quoting matters. > > This patch fixes it by explicitly calling memtodest for the minus > sign. > > Signed-off-by: Herbert Xu This was buggy. Here is an update. ---8<--- The minus sign generated from arithmetic expansion is currently unquoted which causes anomalies when the result is used in where the quoting matters. This patch fixes it by explicitly calling memtodest for the minus sign. Signed-off-by: Herbert Xu diff --git a/src/expand.c b/src/expand.c index 7a51766..7ed1bc0 100644 --- a/src/expand.c +++ b/src/expand.c @@ -490,7 +490,14 @@ expari(int flag) result = arith(p + 1); popstackmark(); - len = cvtnum(result); + len = 0; + if (result < 0) { + memtodest("-", 1, flag); + result = -result; + len++; + } + + len += cvtnum(result); if (likely(!(flag & EXP_QUOTED))) recordregion(begoff, begoff + len, 0); -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
expand: Escape minus sign in arithmetic expansion
The minus sign generated from arithmetic expansion is currently unquoted which causes anomalies when the result is used in where the quoting matters. This patch fixes it by explicitly calling memtodest for the minus sign. Signed-off-by: Herbert Xudiff --git a/src/expand.c b/src/expand.c index c565646..a8bc142 100644 --- a/src/expand.c +++ b/src/expand.c @@ -490,6 +490,11 @@ expari(int flag) result = arith(p + 1); popstackmark(); + if (result < 0) { + memtodest("-", 1, flag); + result = -result; + } + len = cvtnum(result); if (likely(!(flag & EXP_QUOTED))) -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html