This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix Perl #126182, out of memory due to infinite pattern recursion
authorYves Orton <demerphq@gmail.com>
Sun, 6 Mar 2016 12:56:44 +0000 (13:56 +0100)
committerYves Orton <demerphq@gmail.com>
Sun, 6 Mar 2016 13:06:08 +0000 (14:06 +0100)
commitba6840fbf2fdde3e7f1bda1a26f46c901f36d5ec
treeb13ed1fefd5dc5bdf2c79711f41cbb320bced2dd
parentd5a00e4af6b155495be31a35728b8fef8e671ebe
fix Perl #126182, out of memory due to infinite pattern recursion

The way we tracked if pattern recursion was infinite did not work
properly. A pattern like

    "a"=~/(.(?2))((?<=(?=(?1)).))/

would loop forever, slowly eat up all available ram as it added
pattern recursion stack frames.

This patch changes the rules for recursion so that recursively
entering a given pattern "subroutine" twice from the same position
fails the match. This means that where previously we might have
seen fatal exception we will now simply fail. This means that

    "aaabbb"=~/a(?R)?b/

succeeds with $& equal to "aaabbb".
regcomp.c
regcomp.h
regexec.c
regexp.h
t/re/pat.t