From a6aef7817b4be38fb5acf5ebd57054c092223092 Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Wed, 13 Jan 2021 21:18:10 +0900 Subject: [PATCH] fix to read just 20 bytes for AuthSwitchRequest data --- sqlx-core/src/mysql/protocol/connect/auth_switch.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/mysql/protocol/connect/auth_switch.rs b/sqlx-core/src/mysql/protocol/connect/auth_switch.rs index da0cc550..757411f5 100644 --- a/sqlx-core/src/mysql/protocol/connect/auth_switch.rs +++ b/sqlx-core/src/mysql/protocol/connect/auth_switch.rs @@ -25,7 +25,16 @@ impl Decode<'_> for AuthSwitchRequest { } let plugin = buf.get_str_nul()?.parse()?; - let data = buf.get_bytes(buf.len()); + + // See: https://github.com/mysql/mysql-server/blob/ea7d2e2d16ac03afdd9cb72a972a95981107bf51/sql/auth/sha2_password.cc#L942 + if buf.len() != 21 { + return Err(err_protocol!( + "expected 21 bytes but found {} bytes", + buf.len() + )); + } + let data = buf.get_bytes(20); + buf.advance(1); // NUL-terminator Ok(Self { plugin, data }) }