From 47d75cdd80133c4e488d293533a124defd645040 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Sun, 25 Feb 2024 02:03:44 +0000 Subject: [PATCH] MDEV-33469 Fix behavior on invalid arguments When passing in an invalid value (e.g. incorrect data type) for a variable, the server startup will fail with misleading error messages. The behavior **before** this change: For server options: - The error message will indicate that the argument is being adjusted to a valid value - Server startup still fails For plugin options: - The error message will indicate that the argument is being adjusted to a valid value - The plugin is still disabled - Server startup fails with a message that it does not recognize the plugin option The behavior **after** this change: For server options: - Output that an invalid argument was provided - Exit server startup For plugin options: - Output that an invalid argument was provided - Disable the plugin - Attempt to continue server startup All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/mysqld_option_err.result | 2 ++ mysql-test/main/mysqld_option_err.test | 6 +++++- mysys/my_getopt.c | 6 +++++- sql/sql_plugin.cc | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/mysqld_option_err.result b/mysql-test/main/mysqld_option_err.result index 13a004b77d1..2ad24ffe195 100644 --- a/mysql-test/main/mysqld_option_err.result +++ b/mysql-test/main/mysqld_option_err.result @@ -11,6 +11,8 @@ Test to see if multiple ambiguous options and invalid arguments will be displaye FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log FOUND 1 /ambiguous option '--character'/ in mysqltest.log FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log +FOUND 1 /Incorrect integer value: '18446744073709551616'/ in mysqltest.log +FOUND 1 /Error while setting value '18446744073709551616' to 'binlog_cache_size'/ in mysqltest.log Test that --help --verbose works Test that --not-known-option --help --verbose gives error Done. diff --git a/mysql-test/main/mysqld_option_err.test b/mysql-test/main/mysqld_option_err.test index 2c77b868ebf..e89eba33199 100644 --- a/mysql-test/main/mysqld_option_err.test +++ b/mysql-test/main/mysqld_option_err.test @@ -61,7 +61,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output --error 1 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 --let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode' --source include/search_pattern_in_file.inc @@ -69,6 +69,10 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --source include/search_pattern_in_file.inc --let SEARCH_PATTERN=option '--bootstrap' cannot take an argument --source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Incorrect integer value: '18446744073709551616' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Error while setting value '18446744073709551616' to 'binlog_cache_size' +--source include/search_pattern_in_file.inc # # Test that an wrong option with --help --verbose gives an error diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index be8a89d2b08..e67407ca188 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -133,7 +133,7 @@ double getopt_ulonglong2double(ulonglong v) return u.dbl; } -#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); continue; } +#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); (*argc)--; continue; } /** Handle command line options. @@ -1077,6 +1077,8 @@ static ulonglong eval_num_suffix_ull(char *argument, static longlong getopt_ll(char *arg, const struct my_option *optp, int *err) { longlong num=eval_num_suffix_ll(arg, err, (char*) optp->name); + if (*err) + return(0); return getopt_ll_limit_value(num, optp, NULL); } @@ -1154,6 +1156,8 @@ longlong getopt_ll_limit_value(longlong num, const struct my_option *optp, static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err) { ulonglong num= eval_num_suffix_ull(arg, err, (char*) optp->name); + if (*err) + return(0); return getopt_ull_limit_value(num, optp, NULL); } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 84ea95305ba..979407bf3ea 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -4258,7 +4258,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, if (unlikely(error)) { - sql_print_error("Parsing options for plugin '%s' failed.", + sql_print_error("Parsing options for plugin '%s' failed. Disabling plugin", tmp->name.str); goto err; }