From b09c89d6d3212187833c579321140af6eb384c4a Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Fri, 15 Sep 2023 09:49:36 +0100 Subject: [PATCH] do_join(): Take a copy of delimiter string in case FETCH on a tied scalar attempts to modify it --- doop.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doop.c b/doop.c index 89a5e38c5506..cdc992702e77 100644 --- a/doop.c +++ b/doop.c @@ -662,7 +662,7 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp) I32 items = sp - mark; STRLEN len; STRLEN delimlen; - const char * const delims = SvPV_const(delim, delimlen); + const char * delims = SvPV_const(delim, delimlen); PERL_ARGS_ASSERT_DO_JOIN; @@ -703,6 +703,13 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp) for (; items > 0; items--,mark++) { STRLEN len; const char *s; + if(*mark == delim) { + /* Take a copy in case delim SV is a tied SV with a + * self-modifying FETCH [GH #21458] + */ + delims = savepvn(delims, delimlen); + SAVEFREEPV(delims); + } sv_catpvn_flags(sv,delims,delimlen,delimflag); s = SvPV_const(*mark,len); sv_catpvn_flags(sv,s,len,