From e30e9fc6280324494585ef079fde5b0e49203b56 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 5 Feb 2024 14:41:44 +0400 Subject: [PATCH] MDEV-33386 Wrong error message on `GRANT .. ON PACKAGE no_such_package ..` When displaying the ER_SP_DOES_NOT_EXIST error, use Sp_handler::type_lex_cstring() to the the underlying object type: - PROCEDURE - FUNCTION - PACKAGE - PACKAGE BODY instead of hard-coded "FUNCTION or PROCEDURE". --- mysql-test/main/grant.result | 4 ++-- mysql-test/main/sp-package-security.result | 13 +++++++++++++ mysql-test/main/sp-package-security.test | 18 ++++++++++++++++++ sql/sp.cc | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/grant.result b/mysql-test/main/grant.result index a4ec3959a9b..f141fa94108 100644 --- a/mysql-test/main/grant.result +++ b/mysql-test/main/grant.result @@ -2662,9 +2662,9 @@ create database mysqltest_db1; create user mysqltest_u1; # Both GRANT statements below should fail with the same error. grant execute on function mysqltest_db1.f1 to mysqltest_u1; -ERROR 42000: FUNCTION or PROCEDURE f1 does not exist +ERROR 42000: FUNCTION f1 does not exist grant execute on procedure mysqltest_db1.p1 to mysqltest_u1; -ERROR 42000: FUNCTION or PROCEDURE p1 does not exist +ERROR 42000: PROCEDURE p1 does not exist # Let us show that GRANT behaviour for routines is consistent # with GRANT behaviour for tables. Attempt to grant privilege # on non-existent table also results in an error. diff --git a/mysql-test/main/sp-package-security.result b/mysql-test/main/sp-package-security.result index 8958a35e6dc..cd859b04b92 100644 --- a/mysql-test/main/sp-package-security.result +++ b/mysql-test/main/sp-package-security.result @@ -1,3 +1,6 @@ +# +# Start of 11.4 tests +# CREATE DATABASE db1; CREATE USER u1@localhost IDENTIFIED BY ''; GRANT SELECT ON db1.* TO u1@localhost; @@ -307,3 +310,13 @@ SESSION_USER() CURRENT_USER() msg root@localhost root@localhost p1.p1 DROP PACKAGE p1; DROP USER xxx@localhost; +# +# MDEV-33386 Wrong error message on `GRANT .. ON PACKAGE no_such_package ..` +# +GRANT EXECUTE ON PACKAGE no_such_package TO PUBLIC; +ERROR 42000: PACKAGE no_such_package does not exist +GRANT EXECUTE ON PACKAGE BODY no_such_package TO PUBLIC; +ERROR 42000: PACKAGE BODY no_such_package does not exist +# +# End of 11.4 tests +# diff --git a/mysql-test/main/sp-package-security.test b/mysql-test/main/sp-package-security.test index c4acb2ce661..52e986dab57 100644 --- a/mysql-test/main/sp-package-security.test +++ b/mysql-test/main/sp-package-security.test @@ -1,6 +1,10 @@ --source include/not_embedded.inc --source include/default_charset.inc +--echo # +--echo # Start of 11.4 tests +--echo # + CREATE DATABASE db1; CREATE USER u1@localhost IDENTIFIED BY ''; GRANT SELECT ON db1.* TO u1@localhost; @@ -320,3 +324,17 @@ DELIMITER ;$$ CALL p1.p1; DROP PACKAGE p1; DROP USER xxx@localhost; + + +--echo # +--echo # MDEV-33386 Wrong error message on `GRANT .. ON PACKAGE no_such_package ..` +--echo # + +--error ER_SP_DOES_NOT_EXIST +GRANT EXECUTE ON PACKAGE no_such_package TO PUBLIC; +--error ER_SP_DOES_NOT_EXIST +GRANT EXECUTE ON PACKAGE BODY no_such_package TO PUBLIC; + +--echo # +--echo # End of 11.4 tests +--echo # diff --git a/sql/sp.cc b/sql/sp.cc index 3bc637b4327..ddaeeb8cb7a 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -2291,7 +2291,7 @@ Sp_handler::sp_exist_routines(THD *thd, TABLE_LIST *routines) const thd->get_stmt_da()->clear_warning_info(thd->query_id); if (! sp_object_found) { - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), type_lex_cstring().str, routine->table_name.str); DBUG_RETURN(TRUE); }