Skip to content

Commit b796c7a

Browse files
pivanoftz70s
authored andcommitted
Put zero filler into the SSL handshake packet. (go-sql-driver#1066)
According to the linked documentation at http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest SSLRequest packet should have zero filler similar to the regular handshake request, but now the driver puts zeros only in the regular request. Luckily vanilla MySQL doesn't rely on this zero filler and doesn't verify its presence, thus the driver worked fine so far. But MySQL can change to rely on zeros at any point. The problem was discovered while testing against a customized MySQL.
1 parent fc12094 commit b796c7a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packets.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
355355
return errors.New("unknown collation")
356356
}
357357

358+
// Filler [23 bytes] (all 0x00)
359+
pos := 13
360+
for ; pos < 13+23; pos++ {
361+
data[pos] = 0
362+
}
363+
358364
// SSL Connection Request Packet
359365
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest
360366
if mc.cfg.tls != nil {
@@ -373,12 +379,6 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
373379
mc.buf.nc = tlsConn
374380
}
375381

376-
// Filler [23 bytes] (all 0x00)
377-
pos := 13
378-
for ; pos < 13+23; pos++ {
379-
data[pos] = 0
380-
}
381-
382382
// User [null terminated string]
383383
if len(mc.cfg.User) > 0 {
384384
pos += copy(data[pos:], mc.cfg.User)

0 commit comments

Comments
 (0)