1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Fix for CONC-317:

Parsing of configuration file fails if key/value pairs contain white spaces.
This commit is contained in:
Georg Richter
2018-04-12 07:00:43 +02:00
committed by Sergei Golubchik
parent f39db18ec3
commit d83802a3ee
3 changed files with 44 additions and 2 deletions

View File

@@ -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)
@@ -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 == '\"')

View File

@@ -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},

View File

@@ -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},