Skip to content

Fix handling of empty auth plugin names #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
mc.cleanup()
return nil, err
}
if plugin == "" {
plugin = defaultAuthPlugin
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PyMySQL/PyMySQL#709 (comment)

When server sent "" as plugin name, it's safe to response "" as plugin_name too.


// Send Client Authentication Packet
authResp, addNUL, err := mc.auth(authData, plugin)
Expand Down
9 changes: 3 additions & 6 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ func (mc *mysqlConn) writePacket(data []byte) error {

// Handshake Initialization Packet
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake
func (mc *mysqlConn) readHandshakePacket() ([]byte, string, error) {
data, err := mc.readPacket()
func (mc *mysqlConn) readHandshakePacket() (data []byte, plugin string, err error) {
data, err = mc.readPacket()
if err != nil {
// for init we can rewrite this to ErrBadConn for sql.Driver to retry, since
// in connection initialization we don't risk retrying non-idempotent actions.
if err == ErrInvalidConn {
return nil, "", driver.ErrBadConn
}
return nil, "", err
return
}

if data[0] == iERR {
Expand Down Expand Up @@ -198,7 +198,6 @@ func (mc *mysqlConn) readHandshakePacket() ([]byte, string, error) {
}
pos += 2

plugin := ""
if len(data) > pos {
// character set [1 byte]
// status flags [2 bytes]
Expand Down Expand Up @@ -236,8 +235,6 @@ func (mc *mysqlConn) readHandshakePacket() ([]byte, string, error) {
return b[:], plugin, nil
}

plugin = defaultAuthPlugin

// make a memory safe copy of the cipher slice
var b [8]byte
copy(b[:], authData)
Expand Down