Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: fix stack mismatch on nonmatching switch statements with lo… #87

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

jow-
Copy link
Owner

@jow- jow- commented Jun 27, 2022

…cals

When a switch statement containing cases with local variable declarations
and no default case is evalulated and none of the the cases matched, the
local variable slots were never initialized but got popped off the stack
when execution resumed after the switch scope, leading to a mismatch in
stack layout between compiler and runtime, causing local variables to
yield wrong values or a stack underflow triggering a segmentation fault.

Solve this issue by patching the last conditional case match jump to hop
beyond the local variable pop instructions when no default case is defined.

Also extend the regression test case dealing with other switch related
stack mismatch issues to cover this particular problem as well.

Signed-off-by: Jo-Philipp Wich [email protected]

…cals

When a switch statement containing cases with local variable declarations
and no default case is evalulated and none of the the cases matched, the
local variable slots were never initialized but got popped off the stack
when execution resumed after the switch scope, leading to a mismatch in
stack layout between compiler and runtime, causing local variables to
yield wrong values or a stack underflow triggering a segmentation fault.

Solve this issue by patching the last conditional case match jump to hop
beyond the local variable pop instructions when no default case is defined.

Also extend the regression test case dealing with other switch related
stack mismatch issues to cover this particular problem as well.

Signed-off-by: Jo-Philipp Wich <[email protected]>
@jow- jow- merged commit f9aa261 into master Jun 28, 2022
@jow- jow- deleted the compiler-fix-switch-stack-mismatch branch June 28, 2022 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant