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

join: be less magical and handle magic with less undefined behaviour #21502

Merged
merged 6 commits into from
Oct 5, 2023

Conversation

tonycoz
Copy link
Contributor

@tonycoz tonycoz commented Sep 21, 2023

Fixes #21458

Also fixed a couple of other minor problems.

This code had a few problems:

- changes to the content of delim from set or overload magic could
  result in the separator between elements changing during the
  process of the join.
- changes to the content of delim which allocated a new PVX
  resulted in access to freed memory
- changes to the flags of delim, the UTF-8 flag in particular, could
  result in an invalid joined string, either mojibake or an invalidly
  encoded upgraded string

To avoid that, we copy the separator, either into a local buffer
if it's large enough, or an allocated buffer, and save the flag we
use, to prevent changes to the delim SV from changing or invalidating
the delimpv value.

Fixes Perl#21458 and some similar problems.
No tests since I don't have the memory.
@tonycoz tonycoz requested review from leonerd and book September 25, 2023 00:24
doop.c Show resolved Hide resolved
t/op/join.t Outdated Show resolved Hide resolved
I changed $n to 2 in each case as a defence against a reasonable
possible optimisation of $x x 1 sharing the PV with $x.
Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Tied separator and arguments in join() give unexpected results
2 participants