Skip to content

Commit

Permalink
Bug #16102788: INDETERMINATE BEHAVIOR DUE TO EMPTY OPTION VALUES
Browse files Browse the repository at this point in the history
Currently mysql programs silently accept empty strings as option values,
e.g. "--port=" will work the same as "--port=0" and -P "" will work the same as
-P 0.
This is unintuitive and can cause a lot of confusion.
Fixed the options collection code to throw an error if the explicit argument to 
an numeric or enum option is empty string.

Test case added.
  • Loading branch information
gkodinov committed Apr 15, 2014
1 parent 90db4da commit 3d8b457
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mysql-test/r/mysql.result
Expand Up @@ -518,5 +518,10 @@ ERROR 1243 (HY000) at line 15: Unknown prepared statement handler (x) given to E
a
1
2
#
# Bug #16102788: INDETERMINATE BEHAVIOR DUE TO EMPTY OPTION VALUES
#
mysql: [ERROR] mysql: Empty value for 'port' specified
mysql: [ERROR] mysql: Empty value for 'port' specified

End of tests
2 changes: 1 addition & 1 deletion mysql-test/suite/federated/federated_plugin-master.opt
@@ -1,2 +1,2 @@
--plugin_dir=$FEDERATED_PLUGIN_DIR
$FEDERATED_PLUGIN_OPT
--loose-federated=ON
14 changes: 14 additions & 0 deletions mysql-test/t/mysql.test
Expand Up @@ -631,5 +631,19 @@ EOF
--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/WL6797_cleanup.sql 2>&1
--remove_file $MYSQLTEST_VARDIR/tmp/WL6797_cleanup.sql


--echo #
--echo # Bug #16102788: INDETERMINATE BEHAVIOR DUE TO EMPTY OPTION VALUES
--echo #

--replace_regex /mysql: .ERROR. [^ ]*: Empty value for 'port' specified/mysql: [ERROR] mysql: Empty value for 'port' specified/
--error 5
--exec $MYSQL --port= -e "SELECT 1" 2>&1

--replace_regex /mysql: .ERROR. [^ ]*: Empty value for 'port' specified/mysql: [ERROR] mysql: Empty value for 'port' specified/
--error 5
--exec $MYSQL -P "" -e "SELECT 1" 2>&1


--echo
--echo End of tests
33 changes: 32 additions & 1 deletion mysys_ssl/my_getopt.cc
Expand Up @@ -709,10 +709,41 @@ static int setval(const struct my_option *opts, void *value, char *argument,
{
int err= 0, res= 0;
bool error= 0;
ulong var_type= opts->var_type & GET_TYPE_MASK;

if (!argument)
argument= enabled_my_option;

/*
Thus check applies only to options that have a defined value
storage pointer.
We do it for numeric types only, as empty value is a valid
option for strings (the only way to reset back to default value).
Note: it does not relate to OPT_ARG/REQUIRED_ARG/NO_ARG, since
--param="" is not generally the same as --param.
TODO: Add an option definition flag to signify whether empty value
(i.e. --param="") is an acceptable value or an error and extend
the check to all options.
*/
if (!*argument &&
(
var_type == GET_INT ||
var_type == GET_UINT ||
var_type == GET_LONG ||
var_type == GET_ULONG ||
var_type == GET_LL ||
var_type == GET_ULL ||
var_type == GET_DOUBLE ||
var_type == GET_ENUM
)
)
{
my_getopt_error_reporter(ERROR_LEVEL,
"%s: Empty value for '%s' specified",
my_progname, opts->name);
return EXIT_ARGUMENT_REQUIRED;
}

if (value)
{
if (set_maximum_value && !(value= opts->u_max_value))
Expand All @@ -723,7 +754,7 @@ static int setval(const struct my_option *opts, void *value, char *argument,
return EXIT_NO_PTR_TO_VARIABLE;
}

switch ((opts->var_type & GET_TYPE_MASK)) {
switch (var_type) {
case GET_BOOL: /* If argument differs from 0, enable option, else disable */
*((my_bool*) value)= get_bool_argument(opts, argument, &error);
if(error)
Expand Down

0 comments on commit 3d8b457

Please sign in to comment.