Skip to content

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 book and leonerd September 25, 2023 00:24
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