Skip to content

Commit 413c6a5

Browse files
authored
Fix can't connect to MySQL 8.0 with long password (#914)
* Fix can't connect to MySQL 8.0 with long password Signed-off-by: lance6716 <[email protected]> * tmp revert Signed-off-by: lance6716 <[email protected]> * revert Signed-off-by: lance6716 <[email protected]> * fix wrong UT Signed-off-by: lance6716 <[email protected]> --------- Signed-off-by: lance6716 <[email protected]>
1 parent 3a665d0 commit 413c6a5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

client/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ func (c *Conn) readInitialHandshake() error {
115115
// the first packet *must* have at least 20 bytes of a scramble.
116116
// if a plugin provided less, we pad it to 20 with zeros
117117
rest := int(authPluginDataLen) - 8
118-
if max := 12 + 1; rest < max {
119-
rest = max
118+
if rest < 13 {
119+
rest = 13
120120
}
121121

122-
authPluginDataPart2 := data[pos : pos+rest]
122+
authPluginDataPart2 := data[pos : pos+rest-1]
123123
pos += rest
124124

125125
c.salt = append(c.salt, authPluginDataPart2...)

client/client_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,16 @@ INSERT INTO field_value_test VALUES (
526526
require.Equal(s.T(), expected[i], v.String())
527527
}
528528
}
529+
530+
func (s *clientTestSuite) TestLongPassword() {
531+
_, err := s.c.Execute("DROP USER IF EXISTS 'test_long_password'@'%'")
532+
require.NoError(s.T(), err)
533+
_, err = s.c.Execute("CREATE USER 'test_long_password'@'%' IDENTIFIED BY '12345678901234567890'")
534+
require.NoError(s.T(), err)
535+
536+
addr := fmt.Sprintf("%s:%s", *test_util.MysqlHost, s.port)
537+
c, err := Connect(addr, "test_long_password", "12345678901234567890", "")
538+
require.NoError(s.T(), err)
539+
err = c.Close()
540+
require.NoError(s.T(), err)
541+
}

0 commit comments

Comments
 (0)