| 1 |
# |
| 2 |
# MDEV-38431: Auth Switch with Long Password Corrupts Database Name |
| 3 |
# |
| 4 |
# When password >= 251 bytes with CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA, |
| 5 |
# the length is encoded in 3 bytes (0xFC + 2 bytes). The server incorrectly |
| 6 |
# calculated the database pointer, causing connection to wrong database. |
| 7 |
# |
| 8 |
# Fix: Use 'passwd + passwd_len' instead of 'db + passwd_len + 1' |
| 9 |
# |
| 10 |
|
| 11 |
--source include/not_embedded.inc |
| 12 |
--source include/have_plugin_auth.inc |
| 13 |
|
| 14 |
--echo # |
| 15 |
--echo # Setup |
| 16 |
--echo # |
| 17 |
CREATE DATABASE mdev38431_db; |
| 18 |
|
| 19 |
--echo # |
| 20 |
--echo # Test 1: Short password - baseline test |
| 21 |
--echo # |
| 22 |
CREATE USER shortuser IDENTIFIED VIA cleartext_plugin_server USING 'secret'; |
| 23 |
GRANT ALL ON *.* TO shortuser; |
| 24 |
|
| 25 |
# Connect with short password and verify database |
| 26 |
--exec $MYSQL -h 127.0.0.1 -P $MASTER_MYPORT --default-auth=mysql_clear_password -u shortuser -p"secret" --database=mdev38431_db -e "SELECT DATABASE() AS db" |
| 27 |
|
| 28 |
--echo # |
| 29 |
--echo # Test 2: Long password 260 bytes (triggers 3-byte LENENC) |
| 30 |
--echo # Before fix: ERROR 1044 Access denied to database 'X' (garbage char) |
| 31 |
--echo # After fix: Connects to mdev38431_db correctly |
| 32 |
--echo # |
| 33 |
|
| 34 |
# Create password with 260 'a' characters |
| 35 |
--let $long_pwd=`SELECT REPEAT('a', 260)` |
| 36 |
eval CREATE USER longuser IDENTIFIED VIA cleartext_plugin_server USING '$long_pwd'; |
| 37 |
GRANT ALL ON *.* TO longuser; |
| 38 |
|
| 39 |
# This connection uses --default-auth=mysql_clear_password to trigger auth switch |
| 40 |
# With a password >= 251 bytes, the client sends password length in 3-byte format |
| 41 |
# The bug caused the server to read database name from wrong offset |
| 42 |
--exec $MYSQL -h 127.0.0.1 -P $MASTER_MYPORT --default-auth=mysql_clear_password -u longuser -p"$long_pwd" --database=mdev38431_db -e "SELECT DATABASE() AS db" |
| 43 |
|
| 44 |
--echo # |
| 45 |
--echo # Test 3: Even longer password 500 bytes |
| 46 |
--echo # |
| 47 |
--let $very_long_pwd=`SELECT REPEAT('b', 500)` |
| 48 |
eval CREATE USER verylonguser IDENTIFIED VIA cleartext_plugin_server USING '$very_long_pwd'; |
| 49 |
GRANT ALL ON *.* TO verylonguser; |
| 50 |
|
| 51 |
--exec $MYSQL -h 127.0.0.1 -P $MASTER_MYPORT --default-auth=mysql_clear_password -u verylonguser -p"$very_long_pwd" --database=mdev38431_db -e "SELECT DATABASE() AS db" |
| 52 |
|
| 53 |
--echo # |
| 54 |
--echo # Cleanup |
| 55 |
--echo # |
| 56 |
DROP USER shortuser, longuser, verylonguser; |
| 57 |
DROP DATABASE mdev38431_db; |