diff --git a/libmariadb/default.c b/libmariadb/default.c index 927c3d88..289f24bd 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -227,7 +227,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp; FILE *fp; uint line=0; - my_bool read_values=0,found_group=0; + my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0; if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3) return 0; /* Ignore wrong paths */ @@ -264,9 +264,15 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, { line++; /* Ignore comment and empty lines */ - for (ptr=buff ; isspace(*ptr) ; ptr++ ) ; + for (ptr=buff ; isspace(*ptr) ; ptr++ ); + if (!is_escaped && (*ptr == '\"' || *ptr== '\'')) + { + is_quoted= !is_quoted; + continue; + } if (*ptr == '#' || *ptr == ';' || !*ptr) continue; + is_escaped= (*ptr == '\\'); if (*ptr == '[') /* Group name */ { found_group=1; @@ -309,6 +315,13 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, for (value++ ; isspace(*value); value++) ; value_end=strend(value); for ( ; isspace(value_end[-1]) ; value_end--) ; + /* remove possible quotes */ + if (*value == '\'' || *value == '\"') + { + value++; + if (value_end[-1] == '\'' || value_end[-1] == '\"') + value_end--; + } if (value_end < value) /* Empty string */ value_end=value; if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3 + diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index 3bbaeef3..00077105 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -27,6 +27,42 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "my_test.h" +static int test_conc66(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + int rc; + FILE *fp; + + if (!(fp= fopen("./my.cnf", "w"))) + return FAIL; + + fprintf(fp, "[conc-66]\n"); + fprintf(fp, "user=conc66\n"); + fprintf(fp, "password='test;#test'\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "conc-66"); + check_mysql_rc(rc, mysql); + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(my, "GRANT ALL ON test.* TO 'conc66'@'localhost' IDENTIFIED BY 'test;#test'"); + check_mysql_rc(rc, my); + rc= mysql_query(my, "FLUSH PRIVILEGES"); + check_mysql_rc(rc, my); + if (!mysql_real_connect(mysql, hostname, NULL, + NULL, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + rc= mysql_query(my, "DROP USER conc66"); + check_mysql_rc(rc, my); + mysql_close(mysql); + return OK; +} + static int test_bug20023(MYSQL *mysql) { int sql_big_selects_orig; @@ -602,6 +638,7 @@ int test_connection_timeout(MYSQL *my) } struct my_tests_st my_tests[] = { + {"test_conc66", test_conc66, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_bug31669", test_bug31669, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_bug33831", test_bug33831, TEST_CONNECTION_NEW, 0, NULL, NULL},