tags 470914 + patch
quit

On Fri, Mar 14, 2008 at 10:07:52PM +0800, WU Zhaojun wrote:
> This bug was found when running the TuxOnIce's "suspend2"
> script  which tries to use dash to evaluate the following
> arithmetic expression:
> 
>     if [ $(($code&3)) -eq 3 ] ; then
> 
> dash reports an error message as follows:
> 
> 'arithmetic expression: expecting primary: "19&3"'
> 
> where "19" is the value of $code.
> 
> It seems dash fails to parse this arithmetic expression
> when there is *no space* between the operands (ie. $code
> and 3) and the operator (ie. &)
> 
> This bug only exists in the compiled "dash" binary distributed
> within the .deb package. However, recompiling the binary file
> from the corresponding .deb source files doesn't have this
> problem.

Recompiling the current version in unstable doesn't work for me.

Hi Herbert, I suggest the attached patch to fix the parsing problem.

Thanks, Gerrit.
>From d5f08fa63ca6c28bbdafa1b57ee782e0e91a6fbb Mon Sep 17 00:00:00 2001
From: Gerrit Pape <[EMAIL PROTECTED]>
Date: Tue, 25 Mar 2008 19:44:45 +0000
Subject: [PATCH] [ARITH] Fix bitwise AND and OR operator parsing

The parser used to skip a byte when parsing the & and | operators, testcase:

 $ dash -c 'echo $((7&1))'
 $ dash -c 'echo $((7& 1))'
 $ dash -c 'echo $((7&11))'
---
 src/arith_yylex.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/arith_yylex.c b/src/arith_yylex.c
index 2c15657..ef8e3e3 100644
--- a/src/arith_yylex.c
+++ b/src/arith_yylex.c
@@ -173,6 +173,7 @@ checkeq:
 		case '|':
 			if (*++buf != '|') {
 				value += ARITH_BOR - '|';
+				--buf;
 				goto checkeq;
 			}
 			value += ARITH_OR - '|';
@@ -180,6 +181,7 @@ checkeq:
 		case '&':
 			if (*++buf != '&') {
 				value += ARITH_BAND - '&';
+				--buf;
 				goto checkeq;
 			}
 			value += ARITH_AND - '&';
-- 
1.5.4.4

Reply via email to