Skip to content

Commit 7ac0064

Browse files
try to fix handling of empty auth plugin names (go-sql-driver#835)
1 parent 749ddf1 commit 7ac0064

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

driver.go

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
105105
mc.cleanup()
106106
return nil, err
107107
}
108+
if plugin == "" {
109+
plugin = defaultAuthPlugin
110+
}
108111

109112
// Send Client Authentication Packet
110113
authResp, addNUL, err := mc.auth(authData, plugin)

packets.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ func (mc *mysqlConn) writePacket(data []byte) error {
154154

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

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

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

239-
plugin = defaultAuthPlugin
240-
241238
// make a memory safe copy of the cipher slice
242239
var b [8]byte
243240
copy(b[:], authData)

0 commit comments

Comments
 (0)