Skip to content

Commit

Permalink
Fix can't connect to MySQL 8.0 with long password (#914)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
lance6716 authored Sep 12, 2024
1 parent 3a665d0 commit 413c6a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func (c *Conn) readInitialHandshake() error {
// the first packet *must* have at least 20 bytes of a scramble.
// if a plugin provided less, we pad it to 20 with zeros
rest := int(authPluginDataLen) - 8
if max := 12 + 1; rest < max {
rest = max
if rest < 13 {
rest = 13
}

authPluginDataPart2 := data[pos : pos+rest]
authPluginDataPart2 := data[pos : pos+rest-1]
pos += rest

c.salt = append(c.salt, authPluginDataPart2...)
Expand Down
13 changes: 13 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,16 @@ INSERT INTO field_value_test VALUES (
require.Equal(s.T(), expected[i], v.String())
}
}

func (s *clientTestSuite) TestLongPassword() {
_, err := s.c.Execute("DROP USER IF EXISTS 'test_long_password'@'%'")
require.NoError(s.T(), err)
_, err = s.c.Execute("CREATE USER 'test_long_password'@'%' IDENTIFIED BY '12345678901234567890'")
require.NoError(s.T(), err)

addr := fmt.Sprintf("%s:%s", *test_util.MysqlHost, s.port)
c, err := Connect(addr, "test_long_password", "12345678901234567890", "")
require.NoError(s.T(), err)
err = c.Close()
require.NoError(s.T(), err)
}

0 comments on commit 413c6a5

Please sign in to comment.