@@ -210,10 +210,12 @@ func (mc *mysqlConn) readHandshakePacket() (data []byte, plugin string, err erro
210
210
if len (data ) > pos {
211
211
// character set [1 byte]
212
212
// status flags [2 bytes]
213
+ pos += 1 + 2
213
214
// capability flags (upper 2 bytes) [2 bytes]
215
+ mc .flags |= clientFlag (binary .LittleEndian .Uint16 (data [pos :pos + 2 ])) << 16
214
216
// length of auth-plugin-data [1 byte]
215
217
// reserved (all [00]) [10 bytes]
216
- pos += 1 + 2 + 2 + 1 + 10
218
+ pos += 2 + 1 + 10
217
219
218
220
// second part of the password cipher [minimum 13 bytes],
219
221
// where len=MAX(13, length of auth-plugin-data - 8)
@@ -261,9 +263,11 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
261
263
clientLocalFiles |
262
264
clientPluginAuth |
263
265
clientMultiResults |
264
- clientConnectAttrs |
266
+ mc . flags & clientConnectAttrs |
265
267
mc .flags & clientLongFlag
266
268
269
+ serverSupportClientConnectAttrs := mc .flags & clientConnectAttrs != 0
270
+
267
271
if mc .cfg .ClientFoundRows {
268
272
clientFlags |= clientFoundRows
269
273
}
@@ -295,11 +299,14 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
295
299
pktLen += n + 1
296
300
}
297
301
302
+ var connAttrsLEI []byte
298
303
// 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
+ if serverSupportClientConnectAttrs {
305
+ var connAttrsLEIBuf [9 ]byte
306
+ connAttrsLen := len (mc .connector .encodedAttributes )
307
+ connAttrsLEI = appendLengthEncodedInteger (connAttrsLEIBuf [:0 ], uint64 (connAttrsLen ))
308
+ pktLen += len (connAttrsLEI ) + len (mc .connector .encodedAttributes )
309
+ }
303
310
304
311
// Calculate packet length and get buffer with that size
305
312
data , err := mc .buf .takeBuffer (pktLen + 4 )
@@ -382,8 +389,10 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
382
389
pos ++
383
390
384
391
// Connection Attributes
385
- pos += copy (data [pos :], connAttrsLEI )
386
- pos += copy (data [pos :], []byte (mc .connector .encodedAttributes ))
392
+ if serverSupportClientConnectAttrs {
393
+ pos += copy (data [pos :], connAttrsLEI )
394
+ pos += copy (data [pos :], []byte (mc .connector .encodedAttributes ))
395
+ }
387
396
388
397
// Send Auth packet
389
398
return mc .writePacket (data [:pos ])
0 commit comments