Skip to content

Commit 79f480a

Browse files
authored
Make protocol version check more strict (#878)
1 parent 1f2f4d8 commit 79f480a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

client/auth.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ func (c *Conn) readInitialHandshake() error {
4242
return errors.Annotate(c.handleErrorPacket(data), "read initial handshake error")
4343
}
4444

45-
if data[0] < MinProtocolVersion {
46-
return errors.Errorf("invalid protocol version %d, must >= 10", data[0])
45+
if data[0] != ClassicProtocolVersion {
46+
if data[0] == XProtocolVersion {
47+
return errors.Errorf(
48+
"invalid protocol version %d, expected 10. "+
49+
"This might be X Protocol, make sure to connect to the right port",
50+
data[0])
51+
}
52+
return errors.Errorf("invalid protocol version %d, expected 10", data[0])
4753
}
4854
pos := 1
4955

mysql/const.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package mysql
22

33
const (
4-
MinProtocolVersion byte = 10
5-
MaxPayloadLen int = 1<<24 - 1
6-
TimeFormat string = "2006-01-02 15:04:05"
4+
ClassicProtocolVersion byte = 10
5+
XProtocolVersion byte = 11
6+
MaxPayloadLen int = 1<<24 - 1
7+
TimeFormat string = "2006-01-02 15:04:05"
78
)
89

910
const (

0 commit comments

Comments
 (0)