Skip to content

Commit

Permalink
auth: do not send 0 byte for mysql_old_password when password is empty (
Browse files Browse the repository at this point in the history
  • Loading branch information
rainingmaster committed Aug 18, 2020
1 parent e2ee2f3 commit 46351a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Soroush Pour <me at soroushjp.com>
Stan Putrya <root.vagner at gmail.com>
Stanley Gunawan <gunawan.stanley at gmail.com>
Steven Hartland <steven.hartland at multiplay.co.uk>
Tan Jinhua <312841925 at qq.com>
Thomas Wodarek <wodarekwebpage at gmail.com>
Tim Ruffles <timruffles at gmail.com>
Tom Jenkinson <tom at tjenkinson.me>
Expand Down
7 changes: 3 additions & 4 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ func pwHash(password []byte) (result [2]uint32) {

// Hash password using insecure pre 4.1 method
func scrambleOldPassword(scramble []byte, password string) []byte {
if len(password) == 0 {
return nil
}

scramble = scramble[:8]

hashPw := pwHash([]byte(password))
Expand Down Expand Up @@ -247,6 +243,9 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
if !mc.cfg.AllowOldPasswords {
return nil, ErrOldPassword
}
if len(mc.cfg.Passwd) == 0 {
return nil, nil
}
// Note: there are edge cases where this should work but doesn't;
// this is currently "wontfix":
// https://github.com/go-sql-driver/mysql/issues/184
Expand Down
4 changes: 2 additions & 2 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ func TestAuthSwitchOldPasswordEmpty(t *testing.T) {
t.Errorf("got error: %v", err)
}

expectedReply := []byte{1, 0, 0, 3, 0}
expectedReply := []byte{0, 0, 0, 3}
if !bytes.Equal(conn.written, expectedReply) {
t.Errorf("got unexpected data: %v", conn.written)
}
Expand All @@ -1184,7 +1184,7 @@ func TestOldAuthSwitchPasswordEmpty(t *testing.T) {
t.Errorf("got error: %v", err)
}

expectedReply := []byte{1, 0, 0, 3, 0}
expectedReply := []byte{0, 0, 0, 3}
if !bytes.Equal(conn.written, expectedReply) {
t.Errorf("got unexpected data: %v", conn.written)
}
Expand Down

0 comments on commit 46351a8

Please sign in to comment.