Repository navigation
Conversation
readHandshakePacket sliced the packet at fixed offsets without checking its length, so a short handshake from the server (for example the two bytes 0x0a 0x00) panicked with "slice bounds out of range" instead of returning an error. Check the length before each fixed-size read and return ErrMalformPkt. Fixes go-sql-driver#1848 Signed-off-by: Andrei Beshkov <andrey.beshkov@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
ChangesHandshake packet validation
Author list
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related issues
Possibly related PRs
Suggested reviewers: Merge Risk:
|
|
i merged #1850 |
Description
readHandshakePacketslices the initial handshake packet at fixed offsets without checking its length, so a short packet from the server (e.g. the two bytes0x0a 0x00) panics withslice bounds out of rangein the caller's goroutine. This checks the length before each fixed-size read and returnsErrMalformPkt, as discussed in #1848. A packet that has the lower capability bytes but nothing after them is still accepted as before.The new test
TestReadHandshakePacketTruncatedfeeds every prefix of a valid handshake (the one fromTestRegression801) toreadHandshakePacketand requires either success orErrMalformPkt/ErrOldProtocol. Without the change it panics.This only covers the initial handshake. The other fixed-offset reads from #1854 are left for a separate PR.
Checklist