From 679b5b5cb75c872ae913b8faa2930878ca9ddfae Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 12 Apr 2018 07:00:43 +0200 Subject: [PATCH] Fix for CONC-317: Parsing of configuration file fails if key/value pairs contain white spaces. --- libmariadb/ma_default.c | 5 ++-- unittest/libmariadb/connection.c | 40 ++++++++++++++++++++++++++++++++ unittest/libmariadb/ps_bugs.c | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/libmariadb/ma_default.c b/libmariadb/ma_default.c index 518819dd..064d1c03 100644 --- a/libmariadb/ma_default.c +++ b/libmariadb/ma_default.c @@ -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 == '\"') diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index 864c8d85..0b72a8ec 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -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}, diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index 8d8a7599..19a3969c 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -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},