Skip to content

Commit 5afaf12

Browse files
richardwilkesjulienschmidt
authored andcommitted
Fix 'panic: runtime error: slice bounds out of range' (#801)
1 parent d03e4c2 commit 5afaf12

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Paul Bonser <misterpib at gmail.com>
6464
Peter Schultz <peter.schultz at classmarkets.com>
6565
Rebecca Chin <rchin at pivotal.io>
6666
Reed Allman <rdallman10 at gmail.com>
67+
Richard Wilkes <wilkes at me.com>
6768
Robert Russell <robert at rrbrussell.com>
6869
Runrioter Wung <runrioter at gmail.com>
6970
Shuode Li <elemount at qq.com>

packets.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,14 @@ func (mc *mysqlConn) readInitPacket() ([]byte, string, error) {
226226
// which seems to work but technically could have a hidden bug.
227227
cipher = append(cipher, data[pos:pos+12]...)
228228
pos += 13
229-
pluginName = string(data[pos : pos+bytes.IndexByte(data[pos:], 0x00)])
230229

231-
// TODO: Verify string termination
232230
// EOF if version (>= 5.5.7 and < 5.5.10) or (>= 5.6.0 and < 5.6.2)
233231
// \NUL otherwise
234-
//
235-
//if data[len(data)-1] == 0 {
236-
// return
237-
//}
238-
//return ErrMalformPkt
232+
if end := bytes.IndexByte(data[pos:], 0x00); end != -1 {
233+
pluginName = string(data[pos : pos+end])
234+
} else {
235+
pluginName = string(data[pos:])
236+
}
239237

240238
// make a memory safe copy of the cipher slice
241239
var b [20]byte

0 commit comments

Comments
 (0)