Skip to content

Commit

Permalink
fix lvalue context for 4-arg substr
Browse files Browse the repository at this point in the history
4-arg substr uses its first arg as an lvalue, but wasn't lvaluifying
it properly.  [perl #115258]
  • Loading branch information
Zefram committed Nov 16, 2017
1 parent a2ed475 commit 19a8de4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion op.c
Expand Up @@ -13385,7 +13385,7 @@ Perl_ck_substr(pTHX_ OP *o)
if (kid->op_type == OP_NULL)
kid = OpSIBLING(kid);
if (kid)
kid->op_flags |= OPf_MOD;
op_lvalue(kid, o->op_type);

}
return o;
Expand Down
28 changes: 27 additions & 1 deletion t/op/substr.t
Expand Up @@ -22,7 +22,7 @@ $SIG{__WARN__} = sub {
}
};

plan(392);
plan(399);

run_tests() unless caller;

Expand Down Expand Up @@ -883,4 +883,30 @@ fresh_perl_is('$0 = "/usr/bin/perl"; substr($0, 0, 0, $0)', '', {}, "(perl #1293
is $x, "\x{100}zzzz", "RT#130624: heap-use-after-free in 4-arg substr (targ)";
}

{
our @ta;
$#ta = -1;
substr($#ta, 0, 2) = 23;
is $#ta, 23;
$#ta = -1;
substr($#ta, 0, 2) =~ s/\A..\z/23/s;
is $#ta, 23;
$#ta = -1;
substr($#ta, 0, 2, 23);
is $#ta, 23;
sub ta_tindex :lvalue { $#ta }
$#ta = -1;
ta_tindex() = 23;
is $#ta, 23;
$#ta = -1;
substr(ta_tindex(), 0, 2) = 23;
is $#ta, 23;
$#ta = -1;
substr(ta_tindex(), 0, 2) =~ s/\A..\z/23/s;
is $#ta, 23;
$#ta = -1;
substr(ta_tindex(), 0, 2, 23);
is $#ta, 23;
}

1;

0 comments on commit 19a8de4

Please sign in to comment.