Skip to content

Commit 1dc3cd1

Browse files
committed
Fix Auth Resnponse packet when addNUL is true
Fixes go-sql-driver#884
1 parent 64cea2f commit 1dc3cd1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packets.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, addNUL bool,
269269

270270
// encode length of the auth plugin data
271271
var authRespLEIBuf [9]byte
272-
authRespLEI := appendLengthEncodedInteger(authRespLEIBuf[:0], uint64(len(authResp)))
272+
authRespLen := len(authResp)
273+
if addNUL {
274+
authRespLen++
275+
}
276+
authRespLEI := appendLengthEncodedInteger(authRespLEIBuf[:0], uint64(authRespLen))
273277
if len(authRespLEI) > 1 {
274278
// if the length can not be written in 1 byte, it must be written as a
275279
// length encoded integer
@@ -364,9 +368,10 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, addNUL bool,
364368

365369
pos += copy(data[pos:], plugin)
366370
data[pos] = 0x00
371+
pos++
367372

368373
// Send Auth packet
369-
return mc.writePacket(data)
374+
return mc.writePacket(data[:pos])
370375
}
371376

372377
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse

0 commit comments

Comments
 (0)