From 696a70c226ddaf4de1a7277e902a40a74670ff40 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 17 Oct 2014 16:12:54 +0400 Subject: [PATCH] Fix and try to avoid "list Package->.." bug --- Bugzilla.pm | 1 - Bugzilla/Object.pm | 2 +- Bugzilla/Util.pm | 7 +++++++ chart.cgi | 2 +- editgroups.cgi | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Bugzilla.pm b/Bugzilla.pm index 3950c54f1..6d0e76c7a 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -83,7 +83,6 @@ sub _die_error { if ($msg =~ /lock wait|deadlock found/i) { - use Data::Dumper; # Log active InnoDB locks my $locks = Bugzilla->dbh->selectall_arrayref('SELECT * FROM information_schema.innodb_locks', {Slice=>{}}); $msg = "InnoDB locks:\n".Dumper($locks)."\n".$msg; diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index b3e888fa2..0e8d2c984 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -173,7 +173,7 @@ sub new_from_list foreach my $id (@$id_list) { detaint_natural($id) || ThrowCodeError('param_must_be_numeric', {function => $class . '::new_from_list'}); - # Too large integers make PostgreSQL crash. + # Too large integers make PostgreSQL crash (FIXME: That's very STRANGE?!!) next if $id > MAX_INT_32; push(@detainted_ids, $id); } diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 665048b86..75bc26b19 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -949,8 +949,15 @@ sub bz_encode_json return $var; } +# Return empty list for undef or expand an arrayref sub list($) { + # If you write "list Package->method->{something}", for example "list Bugzilla->input_params->{arg}", + # Perl parses it as "(list Package)->method->{something}". But most Bugzilla modules use Bugzilla::Util + # and thus have list() imported in their namespace, so (list Package) gets happily executed and you + # just get "Package->method->{something}" without list(). + # Trry to fight it by checking if the calling context wants a list. + wantarray or die "Possible bug: Bugzilla::Util::list() called without wantarray. Do not write 'list Package->method->...'"; my ($array) = @_; return () unless defined $array; return ($array) if ref $array ne 'ARRAY'; diff --git a/chart.cgi b/chart.cgi index 1e2c9819d..c1a45b05e 100755 --- a/chart.cgi +++ b/chart.cgi @@ -269,7 +269,7 @@ exit; # Find any selected series and return either the first or all of them. sub getAndValidateSeriesIDs { - my @series_ids = grep /^\d+$/, list Bugzilla->input_params->{name}; + my @series_ids = grep /^\d+$/, list(Bugzilla->input_params->{name}); return wantarray ? @series_ids : $series_ids[0]; } diff --git a/editgroups.cgi b/editgroups.cgi index c71c98b7b..1d3627f76 100755 --- a/editgroups.cgi +++ b/editgroups.cgi @@ -429,7 +429,7 @@ sub _do_add $current = $group->grant_direct($type); } - my $add_items = Bugzilla::Group->new_from_list([ list Bugzilla->input_params->{$field} ]); + my $add_items = Bugzilla::Group->new_from_list([ list(Bugzilla->input_params->{$field}) ]); foreach my $add (@$add_items) { @@ -450,7 +450,7 @@ sub _do_add sub _do_remove { my ($group, $changes, $sth_delete, $field, $type, $reverse) = @_; - my $remove_items = Bugzilla::Group->new_from_list([ list Bugzilla->input_params->{$field} ]); + my $remove_items = Bugzilla::Group->new_from_list([ list(Bugzilla->input_params->{$field}) ]); foreach my $remove (@$remove_items) {