Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash on arith 'for' with one ';' (re: 1a30a27)
We weren't done yet after fixing the infinite loop. The fix unmasked another crashing bug that has been in ksh since forever: $ ksh -c 'for((;));do :;done' Memory fault $ ksh -c 'for((1;));do :;done' Memory fault Any arithmetic 'for' with just one ';' in it, instead of the expected two, will crash the shell. This bug was masked by the infinite loop introduced in f8f2c4b and unmasked by 1a30a27, but it has been in ksh93 since forever. Analysis: arithfor() counts the semicolins in n and expects n==2. But its test (fcpeek(-1)!=',') does not work if there is one semicolon instead of the expected two; the sh_lexskip() call does not advance the input pointer in that case so the test remains true and 'n' ends up as 2 even if there is only one ';'. What happens in that case, now that we no longer throw a syntax error in sh_lex() lex.c:347/375, is that the loop breaks (lines 377, 1247) and the token is set to zero (lines 1458, 1514). So that is what we need to test for in arithfor(). src/cmd/ksh93/sh/parse.c: arithfor(): - Replace the broken check; break the loop if lexp->token is zero after the sh_lexskip call, so that we can throw the expected syntax error if n < 2, after restoring state (on lines 784-788).
- Loading branch information