From 8a269ee4f97af496886e5cf535fd4fd3bef242f3 Mon Sep 17 00:00:00 2001 From: Herman Lee Date: Thu, 19 Dec 2019 17:23:51 -0800 Subject: [PATCH] Fix counter leak in nonsuper_connections (#1069) Summary: If a non-super user connects to mysqld with an invalid database name, nonsuper_connections is incremented, but never decremented. Squash with D13987618 8.0 porting notes: Since nonsuper_connections is already decremented by calling release_user_connection(), changes to the code are not needed. Test is ported though to make sure the leak won't appear again. Reference Patch: https://github.com/facebook/mysql-5.6/commit/3cc5162fdc2 Pull Request resolved: https://github.com/facebook/mysql-5.6/pull/1069 Reviewed By: yizhang82 Differential Revision: D19129736 Pulled By: hermanlee fbshipit-source-id: 64a9117411a --- mysql-test/r/max_nonsuper_connections.result | 21 ++++++++++++++++++++ mysql-test/t/max_nonsuper_connections.test | 11 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/mysql-test/r/max_nonsuper_connections.result b/mysql-test/r/max_nonsuper_connections.result index 081a02f0f221..862a52265024 100644 --- a/mysql-test/r/max_nonsuper_connections.result +++ b/mysql-test/r/max_nonsuper_connections.result @@ -51,6 +51,27 @@ disconnect con4; disconnect con3; disconnect con2; disconnect con1; +Verifying nonsuper_connections is decremented when db is denied +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' +ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' connection default; connect con$i, localhost, test_user,,test; connect con$i, localhost, test_user,,test; diff --git a/mysql-test/t/max_nonsuper_connections.test b/mysql-test/t/max_nonsuper_connections.test index 083722886305..680387e80e9e 100644 --- a/mysql-test/t/max_nonsuper_connections.test +++ b/mysql-test/t/max_nonsuper_connections.test @@ -99,6 +99,17 @@ while ($i) dec $i; } +# Verify counter leak is fixed when permission to a database is denied +--echo Verifying nonsuper_connections is decremented when db is denied +--disable_query_log +--let $i = 20 +--while ($i) { + --error ER_DBACCESS_DENIED_ERROR + --connect (con_denied_$i, localhost, test_user,,bogus_db) + --dec $i +--} +--enable_query_log + # able to refill up max_nonsuper_connections connection default; let $i = 10;