Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
12 changes: 5 additions & 7 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant moving the comment here (add an extra blank line above). Besides that, the changes LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... ok, will do

pluginName = string(data[pos : pos+end])
} else {
pluginName = string(data[pos:])
}

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