Skip to content

Commit

Permalink
Fix for CONC-317:
Browse files Browse the repository at this point in the history
Parsing of configuration file fails if key/value pairs contain white spaces.
  • Loading branch information
9EOR9 authored and vuvova committed May 12, 2018
1 parent f39db18 commit d83802a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libmariadb/ma_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static my_bool _mariadb_read_options_from_file(MYSQL *mysql,
if (!key)
key= ptr;
for ( ; isspace(end[-1]) ; end--) ;

*end= 0;
if (!value)
{
if (!key)
Expand All @@ -220,8 +220,9 @@ static my_bool _mariadb_read_options_from_file(MYSQL *mysql,
value++;
ptr= value;
for ( ; isspace(*value); value++) ;
optval= value;
value_end=strchr(value, '\0');
*value_end= 0;
optval= ptr;
for ( ; isspace(value_end[-1]) ; value_end--) ;
/* remove possible quotes */
if (*value == '\'' || *value == '\"')
Expand Down
40 changes: 40 additions & 0 deletions unittest/libmariadb/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,48 @@ static int test_conc315(MYSQL *mysql)
return OK;
}

static int test_conc317(MYSQL *unused __attribute__((unused)))
{
MYSQL *mysql;
my_bool reconnect = 0;
FILE *fp= NULL;
const char *env= getenv("MYSQL_TMP_DIR");
char cnf_file1[FN_REFLEN + 1];

if (travis_test)
return SKIP;

if (!env)
env= "/tmp";

setenv("HOME", env, 1);

snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR);

FAIL_IF(!access(cnf_file1, R_OK), "access");

mysql= mysql_init(NULL);
fp= fopen(cnf_file1, "w");
FAIL_IF(!fp, "fopen");

fprintf(fp, "[client]\ndefault-character-set = latin2\nreconnect= 1\n");
fclose(fp);

mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "");
my_test_connect(mysql, hostname, username, password,
schema, 0, socketname, 0);

remove(cnf_file1);

FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2");
mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect);
FAIL_IF(reconnect != 1, "expected reconnect=1");
mysql_close(mysql);
return OK;
}

struct my_tests_st my_tests[] = {
{"test_conc317", test_conc317, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc315", test_conc315, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_expired_pw", test_expired_pw, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc276", test_conc276, TEST_CONNECTION_NONE, 0, NULL, NULL},
Expand Down
1 change: 1 addition & 0 deletions unittest/libmariadb/ps_bugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4639,6 +4639,7 @@ static int test_mdev14165(MYSQL *mysql)
}

struct my_tests_st my_tests[] = {
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_mdev14165", test_mdev14165, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc217", test_conc217, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
Expand Down

0 comments on commit d83802a

Please sign in to comment.