Attachment #237449: Patch 2.1.2 for 2.22 for bug #340538

View | Details | Raw Unified | Return to bug 340538
Collapse All | Expand All

(-)globals.pl (+2 lines)
Line     Link Here 
 Lines 401-406    Link Here 
401
    } elsif ((defined $matchpassword) && ($password ne $matchpassword)) {
401
    } elsif ((defined $matchpassword) && ($password ne $matchpassword)) {
402
        ThrowUserError("passwords_dont_match");
402
        ThrowUserError("passwords_dont_match");
403
    }
403
    }
404
    # Having done these checks makes us consider the password untainted.
405
    trick_taint($_[0]);
404
}
406
}
405
407
406
sub DBID_to_name {
408
sub DBID_to_name {
(-)token.cgi (-17 / +17 lines)
Line     Link Here 
 Lines 67-75    Link Here 
67
  $::token = $cgi->param('t');
67
  $::token = $cgi->param('t');
68
  
68
  
69
  # Make sure the token contains only valid characters in the right amount.
69
  # Make sure the token contains only valid characters in the right amount.
70
  # Validate password will throw an error if token is invalid
70
  # ValidatePassword will throw an error if token is invalid
71
  ValidatePassword($::token);
71
  ValidatePassword($::token);
72
  trick_taint($::token); # Only used in placeholders
73
72
74
  Bugzilla::Token::CleanTokenTable();
73
  Bugzilla::Token::CleanTokenTable();
75
74
 Lines 99-106    Link Here 
99
# If the user is requesting a password change, make sure they submitted
98
# If the user is requesting a password change, make sure they submitted
100
# their login name and it exists in the database, and that the DB module is in
99
# their login name and it exists in the database, and that the DB module is in
101
# the list of allowed verification methods.
100
# the list of allowed verification methods.
101
my $login_name;
102
if ( $::action eq 'reqpw' ) {
102
if ( $::action eq 'reqpw' ) {
103
    defined $cgi->param('loginname')
103
    $login_name = $cgi->param('loginname');
104
    defined $login_name
104
      || ThrowUserError("login_needed_for_password_change");
105
      || ThrowUserError("login_needed_for_password_change");
105
106
106
    # check verification methods
107
    # check verification methods
 Lines 108-134    Link Here 
108
        ThrowUserError("password_change_requests_not_allowed");
109
        ThrowUserError("password_change_requests_not_allowed");
109
    }
110
    }
110
111
111
    # Make sure the login name looks like an email address.
112
    validate_email_syntax($login_name)
112
    validate_email_syntax($cgi->param('loginname'))
113
      || ThrowUserError('illegal_email_address', {addr => $login_name});
113
      || ThrowUserError('illegal_email_address',
114
                        {addr => $cgi->param('loginname')});
115
114
116
    my $loginname = $cgi->param('loginname');
117
    trick_taint($loginname); # Used only in a placeholder
118
    my ($user_id) = $dbh->selectrow_array('SELECT userid FROM profiles WHERE ' .
115
    my ($user_id) = $dbh->selectrow_array('SELECT userid FROM profiles WHERE ' .
119
                                          $dbh->sql_istrcmp('login_name', '?'),
116
                                          $dbh->sql_istrcmp('login_name', '?'),
120
                                          undef, $loginname);
117
                                          undef, $login_name);
121
    $user_id || ThrowUserError("account_inexistent");
118
    $user_id || ThrowUserError("account_inexistent");
122
}
119
}
123
120
124
# If the user is changing their password, make sure they submitted a new
121
# If the user is changing their password, make sure they submitted a new
125
# password and that the new password is valid.
122
# password and that the new password is valid.
123
my $password;
126
if ( $::action eq 'chgpw' ) {
124
if ( $::action eq 'chgpw' ) {
127
    defined $cgi->param('password')
125
    $password = $cgi->param('password');
126
    defined $password
128
      && defined $cgi->param('matchpassword')
127
      && defined $cgi->param('matchpassword')
129
      || ThrowUserError("require_new_password");
128
      || ThrowUserError("require_new_password");
130
129
131
    ValidatePassword($cgi->param('password'), $cgi->param('matchpassword'));
130
    ValidatePassword($password, $cgi->param('matchpassword'));
132
}
131
}
133
132
134
################################################################################
133
################################################################################
 Lines 140-152    Link Here 
140
# that variable and runs the appropriate code.
139
# that variable and runs the appropriate code.
141
140
142
if ($::action eq 'reqpw') { 
141
if ($::action eq 'reqpw') { 
143
    requestChangePassword(); 
142
    requestChangePassword($login_name);
144
} elsif ($::action eq 'cfmpw') { 
143
} elsif ($::action eq 'cfmpw') { 
145
    confirmChangePassword(); 
144
    confirmChangePassword(); 
146
} elsif ($::action eq 'cxlpw') { 
145
} elsif ($::action eq 'cxlpw') { 
147
    cancelChangePassword(); 
146
    cancelChangePassword(); 
148
} elsif ($::action eq 'chgpw') { 
147
} elsif ($::action eq 'chgpw') { 
149
    changePassword(); 
148
    changePassword($password);
150
} elsif ($::action eq 'cfmem') {
149
} elsif ($::action eq 'cfmem') {
151
    confirmChangeEmail();
150
    confirmChangeEmail();
152
} elsif ($::action eq 'cxlem') {
151
} elsif ($::action eq 'cxlem') {
 Lines 167-173    Link Here 
167
################################################################################
166
################################################################################
168
167
169
sub requestChangePassword {
168
sub requestChangePassword {
170
    Bugzilla::Token::IssuePasswordToken($cgi->param('loginname'));
169
    my ($login_name) = @_;
170
    Bugzilla::Token::IssuePasswordToken($login_name);
171
171
172
    $vars->{'message'} = "password_change_request";
172
    $vars->{'message'} = "password_change_request";
173
173
 Lines 194-204    Link Here 
194
}
194
}
195
195
196
sub changePassword {
196
sub changePassword {
197
    my ($password) = @_;
197
    my $dbh = Bugzilla->dbh;
198
    my $dbh = Bugzilla->dbh;
198
199
199
    # Create a crypted version of the new password
200
    # Create a crypted version of the new password
200
    my $cryptedpassword = bz_crypt($cgi->param('password'));
201
    my $cryptedpassword = bz_crypt($password);
201
    trick_taint($cryptedpassword); # Used only in a placeholder
202
202
203
    # Get the user's ID from the tokens table.
203
    # Get the user's ID from the tokens table.
204
    my ($userid) = $dbh->selectrow_array('SELECT userid FROM tokens
204
    my ($userid) = $dbh->selectrow_array('SELECT userid FROM tokens
(-)Bugzilla/Util.pm (+4 lines)
Line     Link Here 
 Lines 381-386    Link Here 
381
    my ($addr) = @_;
381
    my ($addr) = @_;
382
    my $match = Param('emailregexp');
382
    my $match = Param('emailregexp');
383
    my $ret = ($addr =~ /$match/ && $addr !~ /[\\\(\)<>&,;:"\[\] \t\r\n]/);
383
    my $ret = ($addr =~ /$match/ && $addr !~ /[\\\(\)<>&,;:"\[\] \t\r\n]/);
384
    if ($ret) {
385
        # We assume these checks to suffice to consider the address untainted.
386
        trick_taint($_[0]);
387
    }
384
    return $ret ? 1 : 0;
388
    return $ret ? 1 : 0;
385
}
389
}
386
390

Return to bug 340538