Skip to content

Commit b09c89d

Browse files
committed
do_join(): Take a copy of delimiter string in case FETCH on a tied scalar attempts to modify it
1 parent 2f7afdc commit b09c89d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doop.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp)
662662
I32 items = sp - mark;
663663
STRLEN len;
664664
STRLEN delimlen;
665-
const char * const delims = SvPV_const(delim, delimlen);
665+
const char * delims = SvPV_const(delim, delimlen);
666666

667667
PERL_ARGS_ASSERT_DO_JOIN;
668668

@@ -703,6 +703,13 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp)
703703
for (; items > 0; items--,mark++) {
704704
STRLEN len;
705705
const char *s;
706+
if(*mark == delim) {
707+
/* Take a copy in case delim SV is a tied SV with a
708+
* self-modifying FETCH [GH #21458]
709+
*/
710+
delims = savepvn(delims, delimlen);
711+
SAVEFREEPV(delims);
712+
}
706713
sv_catpvn_flags(sv,delims,delimlen,delimflag);
707714
s = SvPV_const(*mark,len);
708715
sv_catpvn_flags(sv,s,len,

0 commit comments

Comments
 (0)