LP#1509479: set a limit on loops in QP's decompose() method
authorGalen Charlton <gmc@esilibrary.com>
Fri, 23 Oct 2015 20:03:07 +0000 (20:03 +0000)
committerDan Scott <dscott@laurentian.ca>
Sat, 24 Oct 2015 03:20:17 +0000 (23:20 -0400)
Following a suggestion of Dan Scott's, add a pair of
suspenders to the belt and enforce an arbitrary limit
of 1000 passes through QP->decompse().

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm

index ba90f18..7f1f235 100644 (file)
@@ -951,8 +951,14 @@ sub decompose {
 
     my $remainder = '';
 
+    my $loops = 0;
     while (!$remainder) {
-        warn '  'x$recursing."Start of the loop. last_type: $last_type, joiner: ".$struct->joiner.", struct: $struct\n" if $self->debug;
+        $loops++;
+        warn '  'x$recursing."Start of the loop. loop: $loops last_type: $last_type, joiner: ".$struct->joiner.", struct: $struct\n" if $self->debug;
+        if ($loops > 1000) { # the most magical of numbers...
+            warn '  'x$recursing." got to $loops loops; aborting\n" if $self->debug;
+            last;
+        }
         if ($last_type eq 'FEND' and $fstart and $fstart !=  $struct) { # fall back further
             $remainder = $_;
             last;