Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mysql-test/main/mysqld_option_err.result
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Test that unknown option is not silently ignored.
Test bad binlog format.
Test empty value for GET_SET option is rejected.
FOUND 1 /Error while setting value '' to 'create_tmp_table_binlog_formats'/ in mysqltest.log
Test bad default storage engine.
Test non-numeric value passed to number option.
Test with invalid path
Expand Down
11 changes: 9 additions & 2 deletions mysql-test/main/mysqld_option_err.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err;
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --log-bin --binlog-format=badformat >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1


--echo Test empty value for GET_SET option is rejected.
--error 13
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --create-tmp-table-binlog-formats='' >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1

--let SEARCH_FILE = $MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log

--let SEARCH_PATTERN=Error while setting value '' to 'create_tmp_table_binlog_formats'
--source include/search_pattern_in_file.inc

--echo Test bad default storage engine.
--error 1
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --default-storage-engine=nonexistentengine >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1
Expand All @@ -50,8 +59,6 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err;
--error 1
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --plugin-maturity=experimental --plugin-load=example=ha_example --plugin-example=FORCE --plugin-example-enum-var=noexist >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1

--let SEARCH_FILE = $MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log

--echo Test to see if multiple unknown options will be displayed in the error output
--error 7
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --nonexistentoption2 --alsononexistent --nonexistentvariable=1 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1
Expand Down
5 changes: 5 additions & 0 deletions mysys/my_getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,11 @@ static int setval(const struct my_option *opts, void *value, char *argument,
}
break;
case GET_SET:
if (!argument[0])
{
res= EXIT_ARGUMENT_INVALID;
goto ret;
}
Comment on lines +877 to +881

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Dereferencing argument without checking if it is NULL can lead to a segmentation fault if the option is processed without an argument. To prevent a potential null pointer dereference, ensure argument is validated before checking its first character. Note that validation logic for configuration variables should explicitly allow empty strings if they are considered valid or represent the default state, so we should only check for NULL here.

      if (!argument)
      {
        res= EXIT_ARGUMENT_INVALID;
        goto ret;
      }
References
  1. Validation logic for configuration variables should explicitly allow empty strings if they are considered valid or represent the default state.

*((ulonglong*)value)= find_typeset(argument, opts->typelib, &err);
if (err)
{
Expand Down
Loading