@@ -210,10 +210,13 @@ func (mc *mysqlConn) readHandshakePacket() (data []byte, plugin string, err erro
210210 if len(data) > pos {
211211 // character set [1 byte]
212212 // status flags [2 bytes]
213+ pos += 3
213214 // capability flags (upper 2 bytes) [2 bytes]
215+ mc.flags |= clientFlag(binary.LittleEndian.Uint16(data[pos:pos+2])) << 16
216+ pos += 2
214217 // length of auth-plugin-data [1 byte]
215218 // reserved (all [00]) [10 bytes]
216- pos += 1 + 2 + 2 + 1 + 10
219+ pos += 11
217220
218221 // second part of the password cipher [minimum 13 bytes],
219222 // where len=MAX(13, length of auth-plugin-data - 8)
@@ -261,9 +264,11 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
261264 clientLocalFiles |
262265 clientPluginAuth |
263266 clientMultiResults |
264- clientConnectAttrs |
267+ mc.flags& clientConnectAttrs |
265268 mc.flags&clientLongFlag
266269
270+ sendConnectAttrs := mc.flags&clientConnectAttrs != 0
271+
267272 if mc.cfg.ClientFoundRows {
268273 clientFlags |= clientFoundRows
269274 }
@@ -296,10 +301,13 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
296301 }
297302
298303 // encode length of the connection attributes
299- var connAttrsLEIBuf [9]byte
300- connAttrsLen := len(mc.connector.encodedAttributes)
301- connAttrsLEI := appendLengthEncodedInteger(connAttrsLEIBuf[:0], uint64(connAttrsLen))
302- pktLen += len(connAttrsLEI) + len(mc.connector.encodedAttributes)
304+ var connAttrsLEI []byte
305+ if sendConnectAttrs {
306+ var connAttrsLEIBuf [9]byte
307+ connAttrsLen := len(mc.connector.encodedAttributes)
308+ connAttrsLEI = appendLengthEncodedInteger(connAttrsLEIBuf[:0], uint64(connAttrsLen))
309+ pktLen += len(connAttrsLEI) + len(mc.connector.encodedAttributes)
310+ }
303311
304312 // Calculate packet length and get buffer with that size
305313 data, err := mc.buf.takeBuffer(pktLen + 4)
@@ -382,8 +390,10 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
382390 pos++
383391
384392 // Connection Attributes
385- pos += copy(data[pos:], connAttrsLEI)
386- pos += copy(data[pos:], []byte(mc.connector.encodedAttributes))
393+ if sendConnectAttrs {
394+ pos += copy(data[pos:], connAttrsLEI)
395+ pos += copy(data[pos:], []byte(mc.connector.encodedAttributes))
396+ }
387397
388398 // Send Auth packet
389399 return mc.writePacket(data[:pos])
0 commit comments