]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 108982: enable taint mode for all user-facing CGI files.
authorjustdave%syndicomm.com <>
Sun, 20 Jan 2002 09:44:34 +0000 (09:44 +0000)
committerjustdave%syndicomm.com <>
Sun, 20 Jan 2002 09:44:34 +0000 (09:44 +0000)
Patch by Brad Baetz <bbaetz@student.usyd.edu.au>
r= jake, justdave

40 files changed:
Attachment.pm
Bug.pm
Bugzilla/Attachment.pm
Bugzilla/Bug.pm
Bugzilla/Token.pm
CGI.pl
Token.pm
attachment.cgi
buglist.cgi
bugzilla.dtd
changepassword.cgi
colchange.cgi
createaccount.cgi
createattachment.cgi
describecomponents.cgi
describekeywords.cgi
doeditparams.cgi
doeditvotes.cgi
duplicates.cgi
enter_bug.cgi
globals.pl
long_list.cgi
move.pl
new_comment.cgi
post_bug.cgi
process_bug.cgi
queryhelp.cgi
quips.cgi
relogin.cgi
reports.cgi
sanitycheck.cgi
show_activity.cgi
show_bug.cgi
showattachment.cgi
showdependencygraph.cgi
showvotes.cgi
t/002goodperl.t
token.cgi
userprefs.cgi
xml.cgi

index 1ba194d77bebd4b3da2c2ffc551eead53afccd8b..acfa52f63026833f35c43faceaefd65c88615ede 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bonsaitools/bin/perl -w
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
diff --git a/Bug.pm b/Bug.pm
index 670b274eb341e358008032bf80d7ccfb41fd0fc7..96ff0b8af6a06f2a089fd9aef3e982332b85ce22 100755 (executable)
--- a/Bug.pm
+++ b/Bug.pm
@@ -1,4 +1,3 @@
-#!/usr/bonsaitools/bin/perl -w
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -75,10 +74,12 @@ sub initBug  {
   my $self = shift();
   my ($bug_id, $user_id) = (@_);
 
-
-  if ( (! defined $bug_id) || (!$bug_id) ) {
-    # no bug number given
-    return {};
+  my $old_bug_id = $bug_id;
+  if ((! defined $bug_id) || (!$bug_id) || (!&::detaint_natural($bug_id))) {
+      # no bug number given
+      $self->{'bug_id'} = $old_bug_id;
+      $self->{'error'} = "InvalidBugId";
+      return $self;
   }
 
 # default userid 0, or get DBID if you used an email address
index 1ba194d77bebd4b3da2c2ffc551eead53afccd8b..acfa52f63026833f35c43faceaefd65c88615ede 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bonsaitools/bin/perl -w
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
index 670b274eb341e358008032bf80d7ccfb41fd0fc7..96ff0b8af6a06f2a089fd9aef3e982332b85ce22 100755 (executable)
@@ -1,4 +1,3 @@
-#!/usr/bonsaitools/bin/perl -w
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -75,10 +74,12 @@ sub initBug  {
   my $self = shift();
   my ($bug_id, $user_id) = (@_);
 
-
-  if ( (! defined $bug_id) || (!$bug_id) ) {
-    # no bug number given
-    return {};
+  my $old_bug_id = $bug_id;
+  if ((! defined $bug_id) || (!$bug_id) || (!&::detaint_natural($bug_id))) {
+      # no bug number given
+      $self->{'bug_id'} = $old_bug_id;
+      $self->{'error'} = "InvalidBugId";
+      return $self;
   }
 
 # default userid 0, or get DBID if you used an email address
index 185884c98829525b305ad886569c887452ff7c77..f2c5fbde73f312ed120408b6dec4ae7fd9da6bb8 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bonsaitools/bin/perl -w
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
diff --git a/CGI.pl b/CGI.pl
index e245c1db423db6dd25e52bbd502b28c6494bcf21..16ec7f2d8f93ccd32e9123e4a1ff3f5534e4c332 100644 (file)
--- a/CGI.pl
+++ b/CGI.pl
@@ -93,6 +93,9 @@ sub url_quote {
 
 
 sub ParseUrlString {
+    # We don't want to detaint the user supplied data...
+    use re 'taint';
+
     my ($buffer, $f, $m) = (@_);
     undef %$f;
     undef %$m;
@@ -118,6 +121,7 @@ sub ParseUrlString {
             $name = $item;
             $value = "";
         }
+
         if ($value ne "") {
             if (defined $f->{$name}) {
                 $f->{$name} .= $value;
@@ -141,7 +145,6 @@ sub ParseUrlString {
     }
 }
 
-
 sub ProcessFormFields {
     my ($buffer) = (@_);
     return ParseUrlString($buffer, \%::FORM, \%::MFORM);
@@ -259,18 +262,18 @@ sub ValidateBugID {
     # Validates and verifies a bug ID, making sure the number is a 
     # positive integer, that it represents an existing bug in the
     # database, and that the user is authorized to access that bug.
+    # We detaint the number here, too
 
-    my ($id) = @_;
-
-    # Make sure the bug number is a positive integer.
-    # Whitespace can be ignored because the SQL server will ignore it.
-    $id =~ /^\s*([1-9][0-9]*)\s*$/
+    $_[0] = trim($_[0]); # Allow whitespace arround the number
+    detaint_natural($_[0])
       || DisplayError("The bug number is invalid. If you are trying to use " .
                       "QuickSearch, you need to enable JavaScript in your " .
                       "browser. To help us fix this limitation, look " .
                       "<a href=\"http://bugzilla.mozilla.org/show_bug.cgi?id=70907\">here</a>.") 
       && exit;
 
+    my ($id) = @_;
+
     # Get the values of the usergroupset and userid global variables
     # and write them to local variables for use within this function,
     # setting those local variables to the default value of zero if
@@ -685,6 +688,8 @@ sub quietly_check_login() {
                     $::COOKIE{"Bugzilla_login"} = $loginname; # Makes sure case
                                                               # is in
                                                               # canonical form.
+                    # We've just verified that this is ok
+                    detaint_natural($::COOKIE{"Bugzilla_logincookie"});
                 } else {
                     $::disabledreason = $disabledtext;
                 }
@@ -1430,6 +1435,8 @@ if (defined $ENV{"REQUEST_METHOD"}) {
 
 
 if (defined $ENV{"HTTP_COOKIE"}) {
+    # Don't trust anything which came in as a cookie
+    use re 'taint';
     foreach my $pair (split(/;/, $ENV{"HTTP_COOKIE"})) {
         $pair = trim($pair);
         if ($pair =~ /^([^=]*)=(.*)$/) {
index 185884c98829525b305ad886569c887452ff7c77..f2c5fbde73f312ed120408b6dec4ae7fd9da6bb8 100644 (file)
--- a/Token.pm
+++ b/Token.pm
@@ -1,4 +1,3 @@
-#!/usr/bonsaitools/bin/perl -w
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
index e5c3f52fe13a09a719ddce707a64210eb9034940..5996aa86d05c8fc612ba7f98811bd1b5fc5499de 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -29,6 +29,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 # Include the Bugzilla CGI and general utility library.
 require "CGI.pl";
 
@@ -139,10 +141,10 @@ exit;
 
 sub validateID
 {
-  # Validate the value of the "id" form field, which must contain a positive
+  # Validate the value of the "id" form field, which must contain an
   # integer that is the ID of an existing attachment.
 
-  $::FORM{'id'} =~ /^[1-9][0-9]*$/
+  detaint_natural($::FORM{'id'})
     || DisplayError("You did not enter a valid attachment number.") 
       && exit;
   
index d74563f252792a7dea36161c8a1d17c9585eaff4..ce67f648ea6359d8247e918b95f2ce672209a76b 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -26,6 +26,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 use Date::Parse;
 
@@ -783,6 +785,11 @@ sub GenerateSQL {
                     die "Internal error: $errstr" if $chart < 0;
                     return Error($errstr);
                 }
+
+                # This is either from the internal chart (in which case we
+                # already know about it), or it was in %chartfields, so it is
+                # a valid field name, which means that its ok.
+                trick_taint($f);
                 $q = SqlQuote($v);
                 my $func;
                 $term = undef;
@@ -1067,7 +1074,15 @@ my @fields = ("bugs.bug_id", "bugs.groupset");
 
 foreach my $c (@collist) {
     if (exists $::needquote{$c}) {
-        push(@fields, "$::key{$c}");
+        # The value we are actually using is $::key{$c}, which was created
+        # using the DefCol() function earlier.  We test for the existance
+        # of $::needsquote{$c} to find out if $c is a legitimate key in the
+        # hashes that were defined by DefCol().  If $::needsquote{$c} exists,
+        # then $c is valid and we can use it to look up our key.
+        # If it doesn't exist, then we know the user is screwing with us   
+        # and we'll just skip it.
+        trick_taint($c);
+        push(@fields, $::key{$c});
     }
 }
 
@@ -1142,6 +1157,7 @@ if (defined $::FORM{'order'} && $::FORM{'order'} ne "") {
     }
     die "Invalid order: $::FORM{'order'}" unless
         $::FORM{'order'} =~ /^([a-zA-Z0-9_., ]+)$/;
+    $::FORM{'order'} = $1; # detaint this, since we've checked it
 
     # Extra special disgusting hack: if we are ordering by target_milestone,
     # change it to order by the sortkey of the target_milestone first.
index a443a953ad89f122c39abf72d85251177e5e8051..21fbb1dabc4c9374b6351300762afc5cf157041e 100644 (file)
@@ -8,7 +8,7 @@ priority, version, rep_platform, assigned_to, delta_ts, component,
 reporter, target_milestone?, bug_severity, creation_ts, qa_contact?, 
 status_whiteboard?, op_sys, short_desc?, keywords*, dependson*, 
 blocks*, cc*, long_desc?, attachment*)>
-<!ATTLIST bug error (NotFound|NotPermitted) #IMPLIED>
+<!ATTLIST bug error (NotFound|NotPermitted|InvalidBugId) #IMPLIED>
 <!ELEMENT bug_id (#PCDATA)>
 <!ELEMENT short_desc (#PCDATA)>
 <!ELEMENT bug_status (#PCDATA)>
index 73ae90350c1b5c72bf373267aa362c2b52fc6fdd..dafe5c1ae7f2808f1bca58bdcdc7f0911d2af14d 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
index f96559885096d1cbe9a0e7ce109e8c70efec10ab..89150b5d41e741d53428213402b6a36aebefe460 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -23,6 +23,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 sub sillyness { # shut up "used only once" warnings
   my $zz = @::legal_keywords;
 }
index 4e5f6d49df82b1bfe7bb98a0e7b4e64c43f9b9ef..839b81fb37308a3784206bf4fe34f7982037fe51 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -26,6 +26,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 # Shut up misguided -w warnings about "used only once":
index d665e4498e16b958bca8e54297c09f9ed4d3a2b6..ed8308cac9b94975fc95c5d4cbfff1fd8f8eecb0 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 use vars %::COOKIE, %::FILENAME;
index bf6f94a3438ffe8805c75ba9e1cb1305e5cff2fd..9a2b99cc23c1be1c72e0eb0ee14c149c15d1c5b4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -25,6 +25,8 @@ use vars %::FORM;
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
index 6e23ca63d96312b49df5e7fc4e392e573eb24920..3475fb6ebdc4ecbb746fca4adfbb5290eb1d13d0 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -23,6 +23,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
index a67175e91e91746f3e80effcf0ad004e40933b55..7390333c0d51ab33bd6c16bda48eb191381d3839 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -23,6 +23,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 require "defparams.pl";
 
index 94c36b8f43f425acad970791f9b66a6a97e4263f..4d88e13c97b6ac630e71b838517f163f3598cbb8 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
@@ -67,9 +69,6 @@ if (0 == @buglist) {
 # minus sign).
 foreach my $id (@buglist) {
   ValidateBugID($id);
-  ($::FORM{$id} =~ /^\d+$/)
-    || DisplayError("Only use non-negative numbers for your bug votes.")
-    && exit;
 }
 
 ######################################################################
@@ -144,7 +143,7 @@ while (MoreSQLData()) {
 }
 SendSQL("delete from votes where who = $who");
 foreach my $id (@buglist) {
-    if ($::FORM{$id} > 0) {
+    if (detaint_natural($::FORM{$id}) && $::FORM{$id} > 0) {
         SendSQL("insert into votes (who, bug_id, count) values ($who, $id, $::FORM{$id})");
     }
     $affected{$id} = 1;
index cd2d14c2aa3fb5289ef4dffa9f66a727de726453..78f29829fc927849bffa8863d75d07300bff41f9 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -27,6 +27,9 @@ use diagnostics;
 use strict;
 use CGI "param";
 use AnyDBM_File;
+
+use lib qw(.);
+
 require "globals.pl";
 require "CGI.pl";
 
index bd55b7363d56e6581851f8e962df5eaa2a9f4c41..f522f89c9b94a526ecc224aa44c1d55307505c79 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -35,6 +35,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 # Shut up misguided -w warnings about "used only once".  "use vars" just
index 87db566c1862060eaaa8d8201c0250e2205fd073..36e1f86f1448e6891bb5c1cdb7162756a25740aa 100644 (file)
@@ -194,8 +194,27 @@ sub SqlLog {
     }
 }
 
+# This is from the perlsec page, slightly modifed to remove a warning
+# From that page:
+#      This function makes use of the fact that the presence of
+#      tainted data anywhere within an expression renders the
+#      entire expression tainted.
+# Don't ask me how it works...
+sub is_tainted {
+    return not eval { my $foo = join('',@_), kill 0; 1; };
+}
+
 sub SendSQL {
     my ($str, $dontshadow) = (@_);
+
+    # Don't use DBI's taint stuff yet, because:
+    # a) We don't want out vars to be tainted (yet)
+    # b) We want to know who called SendSQL...
+    # Is there a better way to do b?
+    if (is_tainted($str)) {
+        die "Attempted to send tainted string to the database";
+    }
+
     my $iswrite =  ($str =~ /^(INSERT|REPLACE|UPDATE|DELETE)/i);
     if ($iswrite && !$::dbwritesallowed) {
         die "Evil code attempted to write stuff to the shadow database.";
index f6182d4393b5ff4fa1a4c62c62e8716fba6d8d39..552457b0625f7e0e1bd1bb060fa3107bda1b584e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 # Shut up misguided -w warnings about "used only once".  "use vars" just
diff --git a/move.pl b/move.pl
index 37b8cb7eff594fdce5b468525dcd38f354f19dd6..9647aee4324dd7bbdf3cb332f7e458c06261cdd1 100755 (executable)
--- a/move.pl
+++ b/move.pl
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -23,6 +23,9 @@
 
 use diagnostics;
 use strict;
+
+use lib qw(.);
+
 use Bug;
 require "CGI.pl";
 $::lockcount = 0;
index 7f428ef80cdb7d1f4e2bb7797a6a9cae1b1206cd..bed11b4721ad15dcb75178fb334655d1aac77b81 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
index b2b84397786f613a8114c0a49053f61527583536..361cba848ec0da3c82fb9861d50187cb6a2a4a97 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -25,6 +25,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 # Shut up misguided -w warnings about "used only once".  For some reason,
index ac2e239efe1759c7f991eeb77acd171225522ba2..13942ca5fd9303239698825e9980c8e676fd0f87 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -29,6 +29,8 @@ use strict;
 my $UserInEditGroupSet = -1;
 my $UserInCanConfirmGroupSet = -1;
 
+use lib qw(.);
+
 require "CGI.pl";
 use RelationSet;
 
@@ -42,6 +44,7 @@ use vars %::versions,
     %::legal_opsys,
     %::legal_platform,
     %::legal_priority,
+    %::settable_resolution,
     %::target_milestone,
     %::legal_severity,
     %::superusergroupset;
@@ -58,13 +61,18 @@ my $requiremilestone = 0;
 # This list will either consist of a single bug number from the "id"
 # form/URL field or a series of numbers from multiple form/URL fields
 # named "id_x" where "x" is the bug number.
+# For each bug being modified, make sure its ID is a valid bug number 
+# representing an existing bug that the user is authorized to access.
 my @idlist;
 if (defined $::FORM{'id'}) {
+    ValidateBugID($::FORM{'id'});
     push @idlist, $::FORM{'id'};
 } else {
     foreach my $i (keys %::FORM) {
         if ($i =~ /^id_([1-9][0-9]*)/) {
-            push @idlist, $1;
+            my $id = $1;
+            ValidateBugID($id);
+            push @idlist, $id;
         }
     }
 }
@@ -74,12 +82,6 @@ scalar(@idlist)
   || DisplayError("You did not select any bugs to modify.")
   && exit;
 
-# For each bug being modified, make sure its ID is a valid bug number 
-# representing an existing bug that the user is authorized to access.
-foreach my $id (@idlist) {
-    ValidateBugID($id);
-}
-
 # If we are duping bugs, let's also make sure that we can change 
 # the original.  This takes care of issue A on bug 96085.
 if (defined $::FORM{'dup_id'} && $::FORM{'knob'} eq "duplicate") {
@@ -538,7 +540,7 @@ sub ChangeResolution {
     my ($str) = (@_);
     if ($str ne $::dontchange) {
         DoComma();
-        $::query .= "resolution = '$str'";
+        $::query .= "resolution = " . SqlQuote($str);
     }
 }
 
@@ -695,6 +697,8 @@ SWITCH: for ($::FORM{'knob'}) {
         last SWITCH;
     };
     /^resolve$/ && CheckonComment( "resolve" ) && do {
+        # Check here, because its the only place we require the resolution
+        CheckFormField(\%::FORM, 'resolution', \@::settable_resolution);
         ChangeStatus('RESOLVED');
         ChangeResolution($::FORM{'resolution'});
         last SWITCH;
@@ -1030,8 +1034,15 @@ The changes made were:
             foreach my $i (split('[\s,]+', $::FORM{$target})) {
                 if ($i eq "") {
                     next;
+                }
 
+                my $orig = $i;
+                if (!detaint_natural($i)) {
+                    PuntTryAgain("$orig is not a legal bug number");
                 }
+
+                # Don't use CanSeeBug, since we want to keep deps to bugs a
+                # user can't see
                 SendSQL("select bug_id from bugs where bug_id = " .
                         SqlQuote($i));
                 my $comp = FetchOneColumn();
@@ -1049,7 +1060,8 @@ The changes made were:
             my @stack = @{$deps{$target}};
             while (@stack) {
                 my $i = shift @stack;
-                SendSQL("select $target from dependencies where $me = $i");
+                SendSQL("select $target from dependencies where $me = " .
+                        SqlQuote($i));
                 while (MoreSQLData()) {
                     my $t = FetchOneColumn();
                     if ($t == $id) {
index 9206bc14480a4a15376c3b851c0a6f23e4c1a430..93cbef755dbd6eee5674d2212fdb596c7df17d0e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -27,6 +27,8 @@ use vars %::FORM;
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
index 897bf32d0ef4737d6053132135940e41d9058f4f..d6fff6cfa68d8bef3af917ee47359a5093351d8f 100755 (executable)
--- a/quips.cgi
+++ b/quips.cgi
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@ use diagnostics;
 use strict;
 use vars ( %::FORM );
 
+use lib qw(.);
+
 require "CGI.pl";
 
 print "Content-type: text/html\n\n";
index 44fae4cc120ab612aa6ff7c8cbbe609e548de43d..091a96e8dd73abab58285985068cf8aa4ced3d8a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -25,6 +25,8 @@ use strict;
 
 use vars %::COOKIE;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 my $cookiepath = Param("cookiepath");
index 861622d73284e166ac285c6aee233792bd7165e2..0bdc062d1d63faa6df837e06d887d26b3481db12 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -41,6 +41,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 eval "use GD";
 my $use_gd = $@ ? 0 : 1;
 eval "use Chart::Lines";
index 1bf10f071d277c4d61f6a1a5fa3c011cc7e4e168..c85a3668e879c9e7112c59be033a9196c53e21cc 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 use vars %::FORM;
index fccc21cd4babffbe7bfd3ac94e44cfc18fcaa80f..f8c55f0a165992da36306c3c2f96816e0cea190a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
index c5b569a459c5ed5062bf43f81165b269a3ad121f..28eb667633beca55f89f528c56d43213ae969cfd 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -23,6 +23,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
index 78143c5507621c5c7a41fad3762ddce5d7f305d1..70f5c6d6641d30b9c0ef67bed866777921941937 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -24,6 +24,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 if (!defined $::FORM{'attach_id'}) {
@@ -43,7 +45,7 @@ ConnectToDatabase();
 
 quietly_check_login();
 
-if ($::FORM{attach_id} !~ /^[1-9][0-9]*$/) {
+if (!detaint_natural($::FORM{attach_id})) {
     DisplayError("Attachment ID should be numeric.");
     exit;
 }
index a10afb8964f49845c687e27f4cd0f3602466043b..4bb90d49707e194cd6b0618fde327efbe35d3f8c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -23,6 +23,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
@@ -168,6 +170,10 @@ node [URL="${urlbase}show_bug.cgi?id=\\N", style=filled, color=lightgrey]
     # Cleanup any old .dot files created from previous runs.
     my $since = time() - 24 * 60 * 60;
     foreach my $f (glob("data/webdot/*.dot")) {
+        # Here we are deleting all old files. All entries are from the
+        # data/webdot/ directory. Since we're deleting the file (not following
+        # symlinks), this can't escape to delete anything it shouldn't
+        trick_taint($f);
         if (ModTime($f) < $since) {
             unlink $f;
         }
index a6928bf84f2caf3fd1aadcbd95f07396226caca3..6ed4bb8e4f2c08eb52f00bee186e9f5cb6b40f67 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -25,6 +25,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 ConnectToDatabase();
@@ -61,7 +63,7 @@ if (defined $::FORM{'voteon'}) {
 
 # Make sure the user ID is a positive integer representing an existing user.
 if (defined $::FORM{'user'}) {
-  $::FORM{'user'} =~ /^([1-9][0-9]*)$/
+  detaint_natural($::FORM{'user'})
     || DisplayError("The user number is invalid.") 
     && exit;
   SendSQL("SELECT 1 FROM profiles WHERE userid = $::FORM{'user'}");
index 9c99a799a2d03d956a765ba371e110b3390ae7a9..09a5f032421b0f82e8077b24b34bf6b91d93d6db 100644 (file)
@@ -55,13 +55,40 @@ foreach my $file (@testitems) {
     }
     my $file_line1 = <FILE>;
     close (FILE);
+
+    $file =~ m/.*\.(.*)/;
+    my $ext = $1;
+
     if ($file_line1 !~ /\/usr\/bonsaitools\/bin\/perl/) {
         ok(1,"$file does not have a shebang"); 
     } else {
-        if ($file_line1 =~ m#/usr/bonsaitools/bin/perl -w#) {
-            ok(1,"$file uses -w");
+        my $flags;
+        if ($file eq "processmail") {
+            # special case processmail, which is tainted checked
+            $flags = "wT";
+        } elsif (!defined $ext || $ext eq "pl") {
+            # standalone programs (eg syncshadowdb) aren't taint checked yet
+            $flags = "w";
+        } elsif ($ext eq "pm") {
+            ok(0, "$file is a module, but has a shebang");
+            next;
+        } elsif ($ext eq "cgi") {
+            # cgi files must be taint checked, but only the user-accessible
+            # ones have been checked so far
+            if ($file =~ m/^edit/) {
+                $flags = "w";
+            } else {
+                $flags = "wT";
+            }
+        } else {
+            ok(0, "$file has shebang but unknown extension");
+            next;
+        }
+
+        if ($file_line1 =~ m#/usr/bonsaitools/bin/perl -$flags#) {
+            ok(1,"$file uses -$flags");
         } else {
-            ok(0,"$file is MISSING -w --WARNING");
+            ok(0,"$file is MISSING -$flags --WARNING");
         }
     }
 }
index 2fed15ad08cae1718654cd9baa993d52fa5871c2..81ae29629d926c1dddddbb4fb60924b376bc3976 100755 (executable)
--- a/token.cgi
+++ b/token.cgi
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -28,6 +28,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 # Include the Bugzilla CGI and general utility library.
 require "CGI.pl";
 
index bc0f1d672bd271e18ed5a94fcb1578132bb20c04..531d57c0eedb3a30873ced2b5c971279a25f1f55 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
@@ -22,6 +22,8 @@
 use diagnostics;
 use strict;
 
+use lib qw(.);
+
 require "CGI.pl";
 
 use RelationSet;
diff --git a/xml.cgi b/xml.cgi
index 51093890e69d96e7111f99f0dd3ae8f8da4c13a9..8b71b38376ca7e1a18ec9d1cc2db074d70feaea7 100755 (executable)
--- a/xml.cgi
+++ b/xml.cgi
@@ -1,4 +1,4 @@
-#!/usr/bonsaitools/bin/perl -w
+#!/usr/bonsaitools/bin/perl -wT
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 #
 # The contents of this file are subject to the Mozilla Public
 
 use diagnostics;
 use strict;
+
+use lib qw(.);
+
 use Bug;
 require "CGI.pl";
 
-if (!defined $::FORM{'id'} || $::FORM{'id'} !~ /^\s*\d+(,\d+)*\s*$/) {
+if (!defined $::FORM{'id'} || !$::FORM{'id'}) {
   print "Content-type: text/html\n\n";
   PutHeader("Display as XML");
   print "<FORM METHOD=GET ACTION=\"xml.cgi\">\n";