From 15817aaf34eb2d338f4b517330efc26c8c12e8c1 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Sun, 23 Feb 2020 20:32:08 -0800 Subject: [PATCH] Put zero filler into the SSL handshake packet. 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. --- packets.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packets.go b/packets.go index 575202ea3..5cbd53298 100644 --- a/packets.go +++ b/packets.go @@ -349,6 +349,12 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string return errors.New("unknown collation") } + // Filler [23 bytes] (all 0x00) + pos := 13 + for ; pos < 13+23; pos++ { + data[pos] = 0 + } + // SSL Connection Request Packet // http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest if mc.cfg.tls != nil { @@ -367,12 +373,6 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string mc.buf.nc = tlsConn } - // Filler [23 bytes] (all 0x00) - pos := 13 - for ; pos < 13+23; pos++ { - data[pos] = 0 - } - // User [null terminated string] if len(mc.cfg.User) > 0 { pos += copy(data[pos:], mc.cfg.User)