diff --git a/webtools/bugzilla/doeditvotes.cgi b/webtools/bugzilla/doeditvotes.cgi index 7b830595a2df..155635723b59 100755 --- a/webtools/bugzilla/doeditvotes.cgi +++ b/webtools/bugzilla/doeditvotes.cgi @@ -25,11 +25,37 @@ use strict; require "CGI.pl"; +ConnectToDatabase(); + confirm_login(); +###################################################################### +# Begin Data/Security Validation +###################################################################### + +# Build a list of bug IDs for which votes have been submitted. Votes +# are submitted in form fields in which the field names are the bug +# IDs and the field values are the number of votes. +my @buglist = grep {/^[1-9][0-9]*$/} keys(%::FORM); + +# Call ValidateBugID on each bug ID to make sure it is a positive +# integer representing an existing bug that the user is authorized +# to access, and make sure the number of votes submitted is also +# a non-negative integer (a series of digits not preceded by a +# minus sign). +foreach my $id (@buglist) { + ValidateBugID($id); + ($::FORM{$id} =~ /^\d+$/) + || DisplayError("Only use non-negative numbers for your bug votes.") + && exit; +} + +###################################################################### +# End Data/Security Validation +###################################################################### + print "Content-type: text/html\n\n"; -ConnectToDatabase(); GetVersionTable(); my $who = DBNameToIdAndCheck($::COOKIE{'Bugzilla_login'}); @@ -43,60 +69,50 @@ if ( (! defined $who) || (!$who) ) { exit(); } -my @buglist = grep {/^\d+$/} keys(%::FORM); +# If the user is voting for bugs, make sure they aren't overstuffing +# the ballot box. +if (scalar(@buglist)) { + SendSQL("SELECT bugs.bug_id, bugs.product, products.maxvotesperbug " . + "FROM bugs, products " . + "WHERE products.product = bugs.product ". + " AND bugs.bug_id IN (" . join(", ", @buglist) . ")"); -if (0 == @buglist) { - PutHeader("Oops?"); - print "Something got confused. Please click Back and try again."; - PutFooter(); - exit(); -} + my %prodcount; -foreach my $id (@buglist) { - $::FORM{$id} = trim($::FORM{$id}); - if ($::FORM{$id} !~ /\d+/ || $::FORM{$id} < 0) { - PutHeader("Numbers only, please"); - print "Only use numeric values for your bug votes.\n"; - print "Please click Back and try again.
Please click Back and try again.
Please click Back and try again.
Please click Back and try again.
Please click Back and try again.