Skip to content

Commit 46351a8

Browse files
auth: do not send 0 byte for mysql_old_password when password is empty (go-sql-driver#1133)
1 parent e2ee2f3 commit 46351a8

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Soroush Pour <me at soroushjp.com>
8686
Stan Putrya <root.vagner at gmail.com>
8787
Stanley Gunawan <gunawan.stanley at gmail.com>
8888
Steven Hartland <steven.hartland at multiplay.co.uk>
89+
Tan Jinhua <312841925 at qq.com>
8990
Thomas Wodarek <wodarekwebpage at gmail.com>
9091
Tim Ruffles <timruffles at gmail.com>
9192
Tom Jenkinson <tom at tjenkinson.me>

auth.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ func pwHash(password []byte) (result [2]uint32) {
136136

137137
// Hash password using insecure pre 4.1 method
138138
func scrambleOldPassword(scramble []byte, password string) []byte {
139-
if len(password) == 0 {
140-
return nil
141-
}
142-
143139
scramble = scramble[:8]
144140

145141
hashPw := pwHash([]byte(password))
@@ -247,6 +243,9 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
247243
if !mc.cfg.AllowOldPasswords {
248244
return nil, ErrOldPassword
249245
}
246+
if len(mc.cfg.Passwd) == 0 {
247+
return nil, nil
248+
}
250249
// Note: there are edge cases where this should work but doesn't;
251250
// this is currently "wontfix":
252251
// https://github.com/go-sql-driver/mysql/issues/184

auth_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ func TestAuthSwitchOldPasswordEmpty(t *testing.T) {
11571157
t.Errorf("got error: %v", err)
11581158
}
11591159

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

1187-
expectedReply := []byte{1, 0, 0, 3, 0}
1187+
expectedReply := []byte{0, 0, 0, 3}
11881188
if !bytes.Equal(conn.written, expectedReply) {
11891189
t.Errorf("got unexpected data: %v", conn.written)
11901190
}

0 commit comments

Comments
 (0)