From 3a2caf6b63c9e32aa7ca67127a134cd4b8071217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 13 May 2024 22:07:46 +0200 Subject: [PATCH] Make protocol version check more strict --- client/auth.go | 10 ++++++++-- mysql/const.go | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/auth.go b/client/auth.go index 5a8f3937a..ab6fe75e7 100644 --- a/client/auth.go +++ b/client/auth.go @@ -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 diff --git a/mysql/const.go b/mysql/const.go index 0cb7fc704..b6da2e736 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -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 (