Skip to content

Commit 9478e26

Browse files
committed
fix: remove last 0 byte for mysql_old_password when password is empty
1 parent 12508c8 commit 9478e26

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

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)