Skip to content

Commit 8ae2bb6

Browse files
committed
BUG 12610784: SET PASSWORD INCORRECTLY KEEP AN OLD EMPTY PASSWORD
The check for empty password in the user account was checking the wrong field. Fixed to check the proper password hash. Test case added. Fixed native_password and old_password plugins that suffered from the same problems. Unambuguated the auth_string ACL_USER member : previously it was used for both password and the authentication string (depending on the plugin). Now fixed to contain either the authentication string specified or empty string.
1 parent 1ab52ab commit 8ae2bb6

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

mysql-test/r/plugin_auth.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,11 @@ ORDER BY COLUMN_NAME;
447447
IS_NULLABLE COLUMN_NAME
448448
YES authentication_string
449449
YES plugin
450+
#
451+
# Bug #12610784: SET PASSWORD INCORRECTLY KEEP AN OLD EMPTY PASSWORD
452+
#
453+
CREATE USER bug12610784@localhost;
454+
SET PASSWORD FOR bug12610784@localhost = PASSWORD('secret');
455+
ERROR 28000: Access denied for user 'bug12610784'@'localhost' (using password: NO)
456+
DROP USER bug12610784@localhost;
450457
End of 5.5 tests

mysql-test/t/plugin_auth.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,19 @@ SELECT IS_NULLABLE, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
512512
ORDER BY COLUMN_NAME;
513513

514514

515+
--echo #
516+
--echo # Bug #12610784: SET PASSWORD INCORRECTLY KEEP AN OLD EMPTY PASSWORD
517+
--echo #
518+
519+
CREATE USER bug12610784@localhost;
520+
SET PASSWORD FOR bug12610784@localhost = PASSWORD('secret');
521+
--disable_query_log
522+
--error ER_ACCESS_DENIED_ERROR
523+
connect(b12610784,localhost,bug12610784,,test);
524+
--enable_query_log
525+
connect(b12610784,localhost,bug12610784,secret,test);
526+
connection default;
527+
disconnect b12610784;
528+
DROP USER bug12610784@localhost;
529+
515530
--echo End of 5.5 tests

sql/sql_acl.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,6 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
825825

826826
char *password= get_field(&mem, table->field[2]);
827827
uint password_len= password ? strlen(password) : 0;
828-
user.auth_string.str= password ? password : const_cast<char*>("");
829-
user.auth_string.length= password_len;
830828
set_user_salt(&user, password, password_len);
831829

832830
if (set_user_plugin(&user, password_len))
@@ -915,7 +913,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
915913
char *tmpstr= get_field(&mem, table->field[next_field++]);
916914
if (tmpstr)
917915
{
918-
if (user.auth_string.length)
916+
if (password_len)
919917
{
920918
sql_print_warning("'user' entry '%s@%s' has both a password "
921919
"and an authentication plugin specified. The "
@@ -1483,8 +1481,8 @@ static void acl_insert_user(const char *user, const char *host,
14831481
{
14841482
acl_user.plugin= password_len == SCRAMBLED_PASSWORD_CHAR_LENGTH_323 ?
14851483
old_password_plugin_name : native_password_plugin_name;
1486-
acl_user.auth_string.str= strmake_root(&mem, password, password_len);
1487-
acl_user.auth_string.length= password_len;
1484+
acl_user.auth_string.str= const_cast<char*>("");
1485+
acl_user.auth_string.length= 0;
14881486
}
14891487

14901488
acl_user.access=privileges;
@@ -8380,7 +8378,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length)
83808378
old_password_plugin, otherwise MySQL will think that server
83818379
and client plugins don't match.
83828380
*/
8383-
if (mpvio->acl_user->auth_string.length == 0)
8381+
if (mpvio->acl_user->salt_len == 0)
83848382
mpvio->acl_user_plugin= old_password_plugin_name;
83858383
}
83868384
}
@@ -8685,7 +8683,7 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
86858683
old_password_plugin, otherwise MySQL will think that server
86868684
and client plugins don't match.
86878685
*/
8688-
if (mpvio->acl_user->auth_string.length == 0)
8686+
if (mpvio->acl_user->salt_len == 0)
86898687
mpvio->acl_user_plugin= old_password_plugin_name;
86908688
}
86918689
}
@@ -9473,7 +9471,7 @@ static int native_password_authenticate(MYSQL_PLUGIN_VIO *vio,
94739471
#endif
94749472

94759473
if (pkt_len == 0) /* no password */
9476-
DBUG_RETURN(info->auth_string[0] ? CR_ERROR : CR_OK);
9474+
DBUG_RETURN(mpvio->acl_user->salt_len != 0 ? CR_ERROR : CR_OK);
94779475

94789476
info->password_used= PASSWORD_USED_YES;
94799477
if (pkt_len == SCRAMBLE_LENGTH)
@@ -9522,7 +9520,7 @@ static int old_password_authenticate(MYSQL_PLUGIN_VIO *vio,
95229520
pkt_len= strnlen((char*)pkt, pkt_len);
95239521

95249522
if (pkt_len == 0) /* no password */
9525-
return info->auth_string[0] ? CR_ERROR : CR_OK;
9523+
return mpvio->acl_user->salt_len != 0 ? CR_ERROR : CR_OK;
95269524

95279525
if (secure_auth(mpvio))
95289526
return CR_ERROR;

0 commit comments

Comments
 (0)