Skip to content

Commit 19bcb54

Browse files
author
Father Chrysostomos
committed
Stop (caller $n)[6] from including final "\n;"
String eval appends "\n;" to the string before evaluating it. (caller $n)[6], which returns the text of the eval, was giving the modified string, rather than the original. In fact, it was returning the actual string buffer that the parser uses. This commit changes it to create a new mortal SV from that string buffer, but without the last two characters. It unfortunately breaks this JAPH: eval'BEGIN{${\(caller 2)[6]}=~y< !"$()+\-145=ACHMT^acfhinrsty{}> <nlrhta"o Pe e,\nkrcrJ uthspeia">}say if+chr(1) -int"145"!=${^MATCH}'
1 parent 1107659 commit 19bcb54

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pp_ctl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,9 @@ PP(pp_caller)
18571857
if (CxTYPE(cx) == CXt_EVAL) {
18581858
/* eval STRING */
18591859
if (CxOLD_OP_TYPE(cx) == OP_ENTEREVAL) {
1860-
PUSHs(cx->blk_eval.cur_text);
1860+
PUSHs(newSVpvn_flags(SvPVX(cx->blk_eval.cur_text),
1861+
SvCUR(cx->blk_eval.cur_text)-2,
1862+
SvUTF8(cx->blk_eval.cur_text)|SVs_TEMP));
18611863
PUSHs(&PL_sv_no);
18621864
}
18631865
/* require */

t/op/caller.t

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BEGIN {
55
chdir 't' if -d 't';
66
@INC = '../lib';
77
require './test.pl';
8-
plan( tests => 86 );
8+
plan( tests => 88 );
99
}
1010

1111
my @c;
@@ -266,6 +266,13 @@ foo::bar
266266
END
267267
"No crash when freed stash is reused for PV with offset hack";
268268

269+
is eval "(caller 0)[6]", "(caller 0)[6]",
270+
'eval text returned by caller does not include \n;';
271+
272+
# PL_linestr should not be modifiable
273+
eval '"${;BEGIN{ ${\(caller 2)[6]} = *foo }}"';
274+
pass "no assertion failure after modifying eval text via caller";
275+
269276
$::testing_caller = 1;
270277

271278
do './op/caller.pl' or die $@;

0 commit comments

Comments
 (0)