Skip to content

Commit 3049aec

Browse files
committed
packets: allow auth responses longer than 255 bytes
1 parent ef34185 commit 3049aec

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packets.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,16 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, addNUL bool,
270270
clientFlags |= clientMultiStatements
271271
}
272272

273-
pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 + 1 + len(authResp) + 21 + 1
273+
// encode length of the auth plugin data
274+
var authRespLEIBuf [9]byte
275+
authRespLEI := appendLengthEncodedInteger(authRespLEIBuf[:0], uint64(len(authResp)))
276+
if len(authRespLEI) > 1 {
277+
// if the length can not be written in 1 byte, it must be written as a
278+
// length encoded integer
279+
clientFlags |= clientPluginAuthLenEncClientData
280+
}
281+
282+
pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 + len(authRespLEI) + len(authResp) + 21 + 1
274283
if addNUL {
275284
pktLen++
276285
}
@@ -342,8 +351,8 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, addNUL bool,
342351
pos++
343352

344353
// Auth Data [length encoded integer]
345-
data[pos] = byte(len(authResp))
346-
pos += 1 + copy(data[pos+1:], authResp)
354+
pos += copy(data[pos:], authRespLEI)
355+
pos += copy(data[pos:], authResp)
347356
if addNUL {
348357
data[pos] = 0x00
349358
pos++

0 commit comments

Comments
 (0)