Bug 12368: Die if the --table value is not allowed.
authorJonathan Druart <jonathan.druart@biblibre.com>
Thu, 12 Jun 2014 07:31:35 +0000 (09:31 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 9 Oct 2015 17:25:58 +0000 (14:25 -0300)
If the table given in parameter is not in the white list, the script
should die rathen than correct to a default value.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
misc/migration_tools/rebuild_zebra.pl

index 67b73c7..dd97170 100755 (executable)
@@ -136,6 +136,13 @@ if (not $biblios and not $authorities) {
     die $msg;
 }
 
+our @tables_allowed_for_select = ( 'biblioitems', 'items', 'biblio' );
+unless ( grep { /^$table$/ } @tables_allowed_for_select ) {
+    die "Cannot specify -t|--table with value '$table'. Only "
+      . ( join ', ', @tables_allowed_for_select )
+      . " are allowed.";
+}
+
 
 #  -v is for verbose, which seems backwards here because of how logging is set
 #    on the CLI of zebraidx.  It works this way.  The default is to not log much
@@ -445,8 +452,7 @@ sub select_all_authorities {
 
 sub select_all_biblios {
     $table = 'biblioitems'
-      if $table ne 'items'
-      and $table ne 'biblio';
+      if grep { /^$table$/ } @tables_allowed_for_select;
     my $strsth = qq{ SELECT biblionumber FROM $table };
     $strsth.=qq{ WHERE $where } if ($where);
     $strsth.=qq{ LIMIT $length } if ($length && !$offset);