Skip to content

Commit f6d9469

Browse files
committed
fix harmless invalid read in Perl_re_compile()
[perl #2460] described a case where electric fence reported an invalid read. This could be reproduced under valgrind with blead and -e'/x/', but only on a non-debugging build. This was because it was checking for certain pairs of nodes (e.g. BOL + END) and wasn't allowing for EXACT nodes, which have the string at the next node position when using a naive NEXTOPER(first). In the non-debugging build, the nodes aren't initialised to zero, and a 1-char EXACT node isn't long enough to spill into the type field of the "next node". Fix this by only using NEXTOPER(first) when we know the first node is kosher.
1 parent 010f0c4 commit f6d9469

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

regcomp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5105,13 +5105,13 @@ Perl_re_compile(pTHX_ SV * const pattern, U32 orig_pm_flags)
51055105
else {
51065106
regnode *first = ri->program + 1;
51075107
U8 fop = OP(first);
5108-
U8 nop = OP(NEXTOPER(first));
5109-
5110-
if (PL_regkind[fop] == NOTHING && nop == END)
5108+
5109+
if (PL_regkind[fop] == NOTHING && OP(NEXTOPER(first)) == END)
51115110
r->extflags |= RXf_NULL;
5112-
else if (PL_regkind[fop] == BOL && nop == END)
5111+
else if (PL_regkind[fop] == BOL && OP(NEXTOPER(first)) == END)
51135112
r->extflags |= RXf_START_ONLY;
5114-
else if (fop == PLUS && nop ==SPACE && OP(regnext(first))==END)
5113+
else if (fop == PLUS && OP(NEXTOPER(first)) == SPACE
5114+
&& OP(regnext(first)) == END)
51155115
r->extflags |= RXf_WHITE;
51165116
}
51175117
#endif

0 commit comments

Comments
 (0)