kohabug 2020 - fix infinite loop in NoZebra on Perl 5.10
authorGalen Charlton <galen.charlton@liblime.com>
Wed, 14 May 2008 22:09:42 +0000 (17:09 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Fri, 16 May 2008 13:18:24 +0000 (08:18 -0500)
commitc6d507f8a9a3a7851c3f74073ef8442146b8dc82
treedfa10bfc138a7517f4acee49bc0da49a4ac70d72
parenta086de137aa0c48d6f1fa6f81274dfa2f71e347c
kohabug 2020 - fix infinite loop in NoZebra on Perl 5.10

When running Koha in NoZebra mode under Perl 5.10, a search
containing a operator (e.g., "mice and men") could cause
a bib search to enter into an infinite loop in NZanalyse.

This possibility arises from the fact that NZanalyse used
to use capture variables from regular expressions without
verifying whether the regular expressions actually matched.
It was compounded by the fact that NZanalyse is recursive;
however, because $1, $2, etc. are dynamically scoped,
*they are not automatically cleared when NZanalyse calls
itself*.

Consequently, if the search string contains a boolean
operator, it would be split into

left = mice
operator = and
right = men

Then NZanalyse would be called recursively on the search
string 'mice'.  However, because $1, $2, and $3 are not
automatically cleared when the function is called again,
and because they are not cleared if a match fails, the code
would fail to recognize that 'mice' is leaf, and would
call NZanalyse('mice') repeatedly, to the promotion of
warm server rooms.

The wrinkle in this is that because of a bug in Perl 5.8, a
failing matches can sometimes alter the capture variables, thus
avoiding the infinite recursion.  However,  this bug was fixed in
Perl 5.10, leading to the NZanalyse bug becoming evident.

The Perl bug is described at http://rt.perl.org/rt3/Public/Bug/Display.html?id=19049
and the fix http://public.activestate.com/cgi-bin/perlbrowse/p/29279.

The fix to the Koha code is to check whether each regexp
that uses capture variables matches or fails, then act
accordingly.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Search.pm