From 5afaf12c4ecbd6e6027400ccd74af424a78d1be4 Mon Sep 17 00:00:00 2001 From: Richard Wilkes Date: Tue, 22 May 2018 10:26:19 -0700 Subject: [PATCH] Fix 'panic: runtime error: slice bounds out of range' (#801) --- AUTHORS | 1 + packets.go | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2f3a8d68f..07d0deee3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -64,6 +64,7 @@ Paul Bonser Peter Schultz Rebecca Chin Reed Allman +Richard Wilkes Robert Russell Runrioter Wung Shuode Li diff --git a/packets.go b/packets.go index 6775d2860..9b76fb040 100644 --- a/packets.go +++ b/packets.go @@ -226,16 +226,14 @@ func (mc *mysqlConn) readInitPacket() ([]byte, string, error) { // which seems to work but technically could have a hidden bug. cipher = append(cipher, data[pos:pos+12]...) pos += 13 - pluginName = string(data[pos : pos+bytes.IndexByte(data[pos:], 0x00)]) - // TODO: Verify string termination // EOF if version (>= 5.5.7 and < 5.5.10) or (>= 5.6.0 and < 5.6.2) // \NUL otherwise - // - //if data[len(data)-1] == 0 { - // return - //} - //return ErrMalformPkt + if end := bytes.IndexByte(data[pos:], 0x00); end != -1 { + pluginName = string(data[pos : pos+end]) + } else { + pluginName = string(data[pos:]) + } // make a memory safe copy of the cipher slice var b [20]byte