Skip to content

Commit

Permalink
Make protocol version check more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed May 13, 2024
1 parent 1f2f4d8 commit 3a2caf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ func (c *Conn) readInitialHandshake() error {
return errors.Annotate(c.handleErrorPacket(data), "read initial handshake error")
}

if data[0] < MinProtocolVersion {
return errors.Errorf("invalid protocol version %d, must >= 10", data[0])
if data[0] != ClassicProtocolVersion {
if data[0] == XProtocolVersion {
return errors.Errorf(
"invalid protocol version %d, expected 10. "+
"This might be X Protocol, make sure to connect to the right port",
data[0])
}
return errors.Errorf("invalid protocol version %d, expected 10", data[0])
}
pos := 1

Expand Down
7 changes: 4 additions & 3 deletions mysql/const.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package mysql

const (
MinProtocolVersion byte = 10
MaxPayloadLen int = 1<<24 - 1
TimeFormat string = "2006-01-02 15:04:05"
ClassicProtocolVersion byte = 10
XProtocolVersion byte = 11
MaxPayloadLen int = 1<<24 - 1
TimeFormat string = "2006-01-02 15:04:05"
)

const (
Expand Down

0 comments on commit 3a2caf6

Please sign in to comment.