Browse Source

Fix 'panic: runtime error: slice bounds out of range' (#801)

Richard Wilkes 7 years ago
parent
commit
5afaf12c4e
2 changed files with 6 additions and 7 deletions
  1. 1 0
      AUTHORS
  2. 5 7
      packets.go

+ 1 - 0
AUTHORS

@@ -64,6 +64,7 @@ Paul Bonser <misterpib at gmail.com>
 Peter Schultz <peter.schultz at classmarkets.com>
 Rebecca Chin <rchin at pivotal.io>
 Reed Allman <rdallman10 at gmail.com>
+Richard Wilkes <wilkes at me.com>
 Robert Russell <robert at rrbrussell.com>
 Runrioter Wung <runrioter at gmail.com>
 Shuode Li <elemount at qq.com>

+ 5 - 7
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