From f3687ccaafe3f4216e832c429c6494d0e76b54ac Mon Sep 17 00:00:00 2001 From: Aryan Arora Date: Fri, 21 Feb 2025 09:31:21 +0530 Subject: [PATCH] MDEV-27126 my_getopt compares option names case sensitively my_getopt compares option names case-sensitively, causing "Unknown option" errors when users type mixed-case options like wsrep_slave_UK_checks in lowercase wsrep_slave_fk_checks. Made the comparison in the getopt_compare_strings() case-insensitive. --- mysql-test/main/my_getopt_case_insensitive.opt | 1 + mysql-test/main/my_getopt_case_insensitive.result | 8 ++++++++ mysql-test/main/my_getopt_case_insensitive.test | 8 ++++++++ .../suite/wsrep/r/wsrep_mixed_case_cmd_arg.result | 8 ++++++++ mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.cnf | 7 +++++++ mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.opt | 1 + .../suite/wsrep/t/wsrep_mixed_case_cmd_arg.test | 11 +++++++++++ mysys/my_getopt.c | 3 ++- 8 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 mysql-test/main/my_getopt_case_insensitive.opt create mode 100644 mysql-test/main/my_getopt_case_insensitive.result create mode 100644 mysql-test/main/my_getopt_case_insensitive.test create mode 100644 mysql-test/suite/wsrep/r/wsrep_mixed_case_cmd_arg.result create mode 100644 mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.cnf create mode 100644 mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.opt create mode 100644 mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.test diff --git a/mysql-test/main/my_getopt_case_insensitive.opt b/mysql-test/main/my_getopt_case_insensitive.opt new file mode 100644 index 00000000000..cadcd15e765 --- /dev/null +++ b/mysql-test/main/my_getopt_case_insensitive.opt @@ -0,0 +1 @@ +--slOw_QuEry_loG=OFF diff --git a/mysql-test/main/my_getopt_case_insensitive.result b/mysql-test/main/my_getopt_case_insensitive.result new file mode 100644 index 00000000000..0ab93079fbf --- /dev/null +++ b/mysql-test/main/my_getopt_case_insensitive.result @@ -0,0 +1,8 @@ +# +# MDEV-27126: my_getopt compares option names case sensitively +# +# Check if the variable is set correctly from options +SELECT @@GLOBAL.slow_query_log; +@@GLOBAL.slow_query_log +0 +# End of test. diff --git a/mysql-test/main/my_getopt_case_insensitive.test b/mysql-test/main/my_getopt_case_insensitive.test new file mode 100644 index 00000000000..5b301375034 --- /dev/null +++ b/mysql-test/main/my_getopt_case_insensitive.test @@ -0,0 +1,8 @@ +--echo # +--echo # MDEV-27126: my_getopt compares option names case sensitively +--echo # + +--echo # Check if the variable is set correctly from options +SELECT @@GLOBAL.slow_query_log; + +--echo # End of test. diff --git a/mysql-test/suite/wsrep/r/wsrep_mixed_case_cmd_arg.result b/mysql-test/suite/wsrep/r/wsrep_mixed_case_cmd_arg.result new file mode 100644 index 00000000000..6eb68ca13a5 --- /dev/null +++ b/mysql-test/suite/wsrep/r/wsrep_mixed_case_cmd_arg.result @@ -0,0 +1,8 @@ +# +# MDEV-27126: my_getopt compares option names case sensitively +# +# Check if the variable is set correctly from options +SELECT @@GLOBAL.wsrep_slave_uk_checks; +@@GLOBAL.wsrep_slave_uk_checks +1 +# End of test. diff --git a/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.cnf b/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.cnf new file mode 100644 index 00000000000..0bf01f81fc5 --- /dev/null +++ b/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.cnf @@ -0,0 +1,7 @@ +!include ../my.cnf + +[mysqld.1] +wsrep-on=ON +wsrep-provider=@ENV.WSREP_PROVIDER +wsrep-cluster-address=gcomm:// + diff --git a/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.opt b/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.opt new file mode 100644 index 00000000000..d13f9f874c9 --- /dev/null +++ b/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.opt @@ -0,0 +1 @@ +--wsrep-slave-uk-checks=1 diff --git a/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.test b/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.test new file mode 100644 index 00000000000..acfe8fd6c45 --- /dev/null +++ b/mysql-test/suite/wsrep/t/wsrep_mixed_case_cmd_arg.test @@ -0,0 +1,11 @@ +--source include/have_innodb.inc +--source include/have_wsrep_provider.inc +--source include/have_binlog_format_row.inc +--echo # +--echo # MDEV-27126: my_getopt compares option names case sensitively +--echo # + +--echo # Check if the variable is set correctly from options +SELECT @@GLOBAL.wsrep_slave_uk_checks; + +--echo # End of test. diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 40cc17d0c22..ada7f883b01 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -962,7 +963,7 @@ my_bool getopt_compare_strings(register const char *s, register const char *t, for (;s != end ; s++, t++) { - if ((*s != '-' ? *s : '_') != (*t != '-' ? *t : '_')) + if ((*s != '-' ? tolower(*s) : '_') != (*t != '-' ? tolower(*t) : '_')) DBUG_RETURN(1); } DBUG_RETURN(0);