Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit f0634d9

Browse files
committed
role: fix method_field_type SEGV
only honor valid pads.
1 parent 1af21b6 commit f0634d9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

op.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19687,7 +19687,9 @@ S_do_method_finalize(pTHX_ const HV *klass, OP *o,
1968719687
IS_TYPE(OpNEXT(arg), METHOD_NAMED))
1968819688
{
1968919689
SV* const meth = cMETHOPx_meth(OpNEXT(arg));
19690-
if (meth && SvPOK(meth) && PAD_COMPNAME(self) && PAD_COMPNAME_TYPE(self)) {
19690+
if (meth && SvPOK(meth) &&
19691+
self <= PadnamelistMAXNAMED(PL_comppad_name) &&
19692+
PAD_COMPNAME(self) && PAD_COMPNAME_TYPE(self)) {
1969119693
const I32 klen = SvUTF8(meth) ? -SvCUR(meth) : SvCUR(meth);
1969219694
const PADOFFSET ix = field_index(klass, SvPVX(meth), klen, FALSE);
1969319695
if (ix != NOT_IN_PAD) {
@@ -20201,18 +20203,17 @@ Perl_method_field_type(pTHX_ OP* o)
2020120203
const I32 klen = SvUTF8(meth) ? -SvCUR(meth) : SvCUR(meth);
2020220204
const PADOFFSET pad = field_pad(klass, SvPVX(meth), klen);
2020320205
OpRETTYPE_set(arg, type_Object);
20204-
if (pad != NOT_IN_PAD) {
20206+
if (pad != NOT_IN_PAD &&
20207+
pad <= PadnamelistMAXNAMED(PL_comppad_name) &&
20208+
PAD_COMPNAME(pad))
20209+
{
2020520210
const char c = *PAD_COMPNAME_PV(pad);
2020620211
if (c == '$')
2020720212
return METHOD_FIELD_SCALAR;
2020820213
else if (c == '@')
2020920214
return METHOD_FIELD_ARRAY;
2021020215
else if (c == '%')
2021120216
return METHOD_FIELD_HASH;
20212-
else /* cannot happen */
20213-
Perl_croak(aTHX_
20214-
"panic: Unknown method field type for %s",
20215-
PAD_COMPNAME_PV(pad));
2021620217
}
2021720218
}
2021820219
}

t/op/class.t

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BEGIN {
55
#require './test.pl';
66
}
77
local($\, $", $,) = (undef, ' ', '');
8-
print "1..33\n";
8+
print "1..35\n";
99
my $test = 1;
1010

1111
# allow has hash fields (YAML::Mo)
@@ -100,8 +100,7 @@ role Foo2 {
100100
method foo2 {
101101
print "ok $test # copied method\n"; $test++;
102102
print $a != 1 ? "not " : "", "ok ", $test++, " # role lex field\n";
103-
#TODO SEGV padfixup
104-
#print $self->a != 1 ? "not " : "", "ok ", $test++, " # role meth field\n";
103+
print $self->a != 1 ? "not " : "", "ok ", $test++, " # role meth field\n";
105104
}
106105
}
107106
class Baz4 does Foo2 {

0 commit comments

Comments
 (0)