Skip to content

Prevent loop exits from unwinding the context/scope stacks beyond a call_sv for smartmatch subs and class constructors #23204

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

Merged
merged 4 commits into from
Apr 19, 2025

Conversation

tonycoz
Copy link
Contributor

@tonycoz tonycoz commented Apr 16, 2025

smartmatch: fail to find the loop instead of crashing

dopoptoloop() or dopoptolabel() would find a loop outside the sub called from call_sv() and rewind the context and save stack to outside the context set up by call_sv(), crashes and panics ensure.

Switching stacks here also starts a new context stack, so the outer loop isn't found and we don't crash.

Most other callers to call_sv() (or call_method() etc) do the same.

I'm not entirely sure about passing flags = 1 to push_stackinfo(), this matches pp_sort, but not other callers.

Fixes #16608

class.c, injected_constructor: prevent loop exits exiting

Using last, next etc would pop the context stack to above the call_sv(), generally resulting in a crash or assertion failure.

The search the context to pop to stops at the top of the current context stack, and PUSHSTACKi() switches to a new stack, preventing the search from finding any loop outside the call_sv()

Similar to #16608

Also fixes a missing -DDEBUGGING string for PERLSI_REGCOMP


  • This set of changes requires a perldelta entry, and it is included.

"MULTICALL",
"REGCOMP",
"SMARTMATCH",
"CONSTRUCTOR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does dump.c need an update?

tonycoz added 4 commits April 19, 2025 17:27
dopoptoloop() or dopoptolabel() would find a loop outside the sub
called from call_sv() and rewind the context and save stack to outside
the context set up by call_sv(), crashes and panics ensure.

Switching stacks here also starts a new context stack, so the outer
loop isn't found and we don't crash.

Most other callers to call_sv() (or call_method() etc) do the same.

I'm not entirely sure about passing flags = 1 to push_stackinfo(),
this matches pp_sort, but not other callers.

Fixes Perl#16608
Using last, next etc would pop the context stack to above the
call_sv(), generally resulting in a crash or assertion failure.

The search the context to pop to stops at the top of the current
context stack, and PUSHSTACKi() switches to a new stack, preventing
the search from finding any loop outside the call_sv()

Similar to Perl#16608
@mauke mauke force-pushed the 16608-leave-smartmatch-sub branch from 4d0024a to 779addc Compare April 19, 2025 15:29
@mauke mauke merged commit b5a660b into Perl:blead Apr 19, 2025
2 checks passed
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.

Segfault when leaving smartmatch'ed sub
4 participants