Skip to content

Commit

Permalink
Merge e333f77 into 749ddf1
Browse files Browse the repository at this point in the history
  • Loading branch information
julienschmidt committed Jul 13, 2018
2 parents 749ddf1 + e333f77 commit 31f1a3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 3 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
mc.cleanup()
return nil, err
}
if plugin == "" {
plugin = defaultAuthPlugin
}

// 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

0 comments on commit 31f1a3d

Please sign in to comment.