From 8ec62514f8a5bff63d8c83f4e8f540862eab253c Mon Sep 17 00:00:00 2001 From: deepthi Date: Mon, 12 Nov 2018 14:11:37 -0800 Subject: [PATCH] If vtgate receives a 0 size packet from a mysql client, it panics. Fix by maintaining the state of currentEphemeralPolicy correctly Signed-off-by: deepthi --- go/mysql/conn.go | 4 ++-- go/mysql/conn_test.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go/mysql/conn.go b/go/mysql/conn.go index 15751f61116..8f24ae53555 100644 --- a/go/mysql/conn.go +++ b/go/mysql/conn.go @@ -279,13 +279,13 @@ func (c *Conn) readEphemeralPacket() ([]byte, error) { return nil, err } + c.currentEphemeralPolicy = ephemeralRead if length == 0 { // This can be caused by the packet after a packet of // exactly size MaxPacketSize. return nil, nil } - c.currentEphemeralPolicy = ephemeralRead // Use the bufPool. if length < MaxPacketSize { c.currentEphemeralBuffer = bufPool.Get(length) @@ -339,13 +339,13 @@ func (c *Conn) readEphemeralPacketDirect() ([]byte, error) { return nil, err } + c.currentEphemeralPolicy = ephemeralRead if length == 0 { // This can be caused by the packet after a packet of // exactly size MaxPacketSize. return nil, nil } - c.currentEphemeralPolicy = ephemeralRead if length < MaxPacketSize { c.currentEphemeralBuffer = bufPool.Get(length) if _, err := io.ReadFull(r, *c.currentEphemeralBuffer); err != nil { diff --git a/go/mysql/conn_test.go b/go/mysql/conn_test.go index 3ff4e0889a7..796798e167f 100644 --- a/go/mysql/conn_test.go +++ b/go/mysql/conn_test.go @@ -170,6 +170,10 @@ func TestPackets(t *testing.T) { data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} verifyPacketComms(t, cConn, sConn, data) + // 0 length packet + data = []byte{} + verifyPacketComms(t, cConn, sConn, data) + // Under the limit, still one packet. data = make([]byte, MaxPacketSize-1) data[0] = 0xab