Skip to content

Commit cfed6c3

Browse files
author
Andy C
committed
[osh/cmd_parse] Fix crash parsing return = x
This is issue #2003. Also reproduce osh-cpp bugs from Koiche.
1 parent b443327 commit cfed6c3

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

osh/cmd_parse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,9 +2427,9 @@ def ParseCommand(self):
24272427
part0 = parts[0]
24282428
if part0.tag() == word_part_e.Literal:
24292429
tok = cast(Token, part0)
2430-
if (match.IsValidVarName(lexer.LazyStr(tok)) and
2431-
self.w_parser.LookPastSpace() == Id.Lit_Equals):
2432-
assert tok.id == Id.Lit_Chars, tok
2430+
if (tok.id == Id.Lit_Chars and
2431+
self.w_parser.LookPastSpace() == Id.Lit_Equals and
2432+
match.IsValidVarName(lexer.LazyStr(tok))):
24332433

24342434
if (len(self.hay_attrs_stack) and
24352435
self.hay_attrs_stack[-1]):

spec/bugs.test.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
## compare_shells: bash dash mksh zsh ash
32
## oils_failures_allowed: 0
43

@@ -360,3 +359,26 @@ PWNED
360359
0
361360
## END
362361

362+
#### printf bugs (Koiche on Zulip)
363+
printf '%x\n' 2147483648
364+
printf '%u\n' 2147483648
365+
## STDOUT:
366+
80000000
367+
2147483648
368+
## END
369+
370+
#### bit shift bug (Koiche on Zulip)
371+
case $SH in dash|ash) exit ;; esac
372+
373+
(( 1 << 32 ))
374+
echo status=$?
375+
376+
(( 1 << 32 )) && echo yes
377+
378+
## STDOUT:
379+
status=0
380+
yes
381+
## END
382+
383+
## N-I dash/ash STDOUT:
384+
## END

spec/ysh-bugs.test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,18 @@ echo $Q
149149
world
150150
## END
151151
152+
153+
#### Parsing crash - bug #2003
154+
155+
set +o errexit
156+
157+
$SH -c 'proc y (;x) { return = x }'
158+
echo status=$?
159+
160+
$SH -c 'func y (;x) { return = x }'
161+
echo status=$?
162+
163+
## STDOUT:
164+
status=2
165+
status=2
166+
## END

0 commit comments

Comments
 (0)