Re: ksh: bug with quoted parameter expansion
On Fri, Jan 26, 2018 at 11:31:40AM +0100, Klemens Nanni wrote: > On Fri, Jan 26, 2018 at 09:41:45AM +0100, Klemens Nanni wrote: > > On Wed, Jan 24, 2018 at 04:15:24PM +0100, m...@josuah.net wrote: > > > I found a bug in ksh's parameter expansion on an edge case: > > > > > > true $(true "${USER#'"'}") > > > > > > /home/sh[4]: no closing quote > > > > > > The problem seems to occurs when all of these conditions are present: > > > > > > 1. On ${var#pattern} or ${var%pattern} parameter expansion > > > 2. When the pattern contains a singly quoted double quote: '"' > > > 3. While expansion occurs withing $(...), (but not `...`) > > > 4. While the expansion is quoted: "${var#pattern}". > > As anton@ pointed out, this is known behaviour. The following will work: > > > > true $(true "${USER#\"}") > > true $(true "${USER#"\""}") > > > Forgot to mention: `` are not subject to this, the bug lives in $() alone. >From the end of ksh(1) BUGS $(command) expressions are currently parsed by finding the closest matching (unquoted) parenthesis. Thus constructs inside $(command) may produce an error. For example, the parenthesis in ‘x);;’ is interpreted as the closing parenthesis in ‘$(case x in x);; *);; esac)’.
Re: ksh: bug with quoted parameter expansion
On Fri, Jan 26, 2018 at 09:41:45AM +0100, Klemens Nanni wrote: > On Wed, Jan 24, 2018 at 04:15:24PM +0100, m...@josuah.net wrote: > > I found a bug in ksh's parameter expansion on an edge case: > > > > true $(true "${USER#'"'}") > > > > /home/sh[4]: no closing quote > > > > The problem seems to occurs when all of these conditions are present: > > > > 1. On ${var#pattern} or ${var%pattern} parameter expansion > > 2. When the pattern contains a singly quoted double quote: '"' > > 3. While expansion occurs withing $(...), (but not `...`) > > 4. While the expansion is quoted: "${var#pattern}". > As anton@ pointed out, this is known behaviour. The following will work: > > true $(true "${USER#\"}") > true $(true "${USER#"\""}") > Forgot to mention: `` are not subject to this, the bug lives in $() alone.
Re: ksh: bug with quoted parameter expansion
On Wed, Jan 24, 2018 at 04:15:24PM +0100, m...@josuah.net wrote: > I found a bug in ksh's parameter expansion on an edge case: > > true $(true "${USER#'"'}") > > /home/sh[4]: no closing quote > > The problem seems to occurs when all of these conditions are present: > > 1. On ${var#pattern} or ${var%pattern} parameter expansion > 2. When the pattern contains a singly quoted double quote: '"' > 3. While expansion occurs withing $(...), (but not `...`) > 4. While the expansion is quoted: "${var#pattern}". As anton@ pointed out, this is known behaviour. The following will work: true $(true "${USER#\"}") true $(true "${USER#"\""}")
Re: ksh: bug with quoted parameter expansion
On Wed, Jan 24, 2018 at 04:15:24PM +0100, m...@josuah.net wrote: > I found a bug in ksh's parameter expansion on an edge case: > > true $(true "${USER#'"'}") > > /home/sh[4]: no closing quote > > The problem seems to occurs when all of these conditions are present: > > 1. On ${var#pattern} or ${var%pattern} parameter expansion > 2. When the pattern contains a singly quoted double quote: '"' > 3. While expansion occurs withing $(...), (but not `...`) > 4. While the expansion is quoted: "${var#pattern}". > > true can be replaced by other commands or var=... > if '"' gets replaced by \", the issue disappear > > The bin/ksh/lex.c seems to use a big switch+goto table with one label > per grammar context. Maybe by jumping from context to context in a > specific pattern like above is producing the issue. > > I did try to figure out where, but I lack time for now. > > I hope the problem does not come from my way to test it and that it > have not been fixed. > > $ uname -a # also tested with /bin/ksh > OpenBSD t470s 6.2 GENERIC.MP#134 amd64 > > $ cvs co bin/ksh/; cd bin/ksh; make > [...] > > $ ./ksh ~/sh > /home/sh[4]: no closing quote For the record, probably related to this: $ pwd /usr/src/bin/ksh $ sed -n 474,479p lex.c case SCSPAREN: /* $( .. ) */ /* todo: deal with $(...) quoting properly * kludge to partly fake quoting inside $(..): doesn't * really work because nested $(..) or ${..} inside * double quotes aren't dealt with. */
ksh: bug with quoted parameter expansion
I found a bug in ksh's parameter expansion on an edge case: true $(true "${USER#'"'}") /home/sh[4]: no closing quote The problem seems to occurs when all of these conditions are present: 1. On ${var#pattern} or ${var%pattern} parameter expansion 2. When the pattern contains a singly quoted double quote: '"' 3. While expansion occurs withing $(...), (but not `...`) 4. While the expansion is quoted: "${var#pattern}". true can be replaced by other commands or var=... if '"' gets replaced by \", the issue disappear The bin/ksh/lex.c seems to use a big switch+goto table with one label per grammar context. Maybe by jumping from context to context in a specific pattern like above is producing the issue. I did try to figure out where, but I lack time for now. I hope the problem does not come from my way to test it and that it have not been fixed. $ uname -a # also tested with /bin/ksh OpenBSD t470s 6.2 GENERIC.MP#134 amd64 $ cvs co bin/ksh/; cd bin/ksh; make [...] $ ./ksh ~/sh /home/sh[4]: no closing quote