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-66: Support for quoted values in configuration file

This commit is contained in:
holzboote@googlemail.com
2014-01-22 22:31:08 +01:00
parent a6ee40ab8e
commit 1b36e6d3b5
2 changed files with 52 additions and 2 deletions

View File

@@ -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; char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp;
FILE *fp; FILE *fp;
uint line=0; 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) if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3)
return 0; /* Ignore wrong paths */ return 0; /* Ignore wrong paths */
@@ -264,9 +264,15 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
{ {
line++; line++;
/* Ignore comment and empty lines */ /* 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) if (*ptr == '#' || *ptr == ';' || !*ptr)
continue; continue;
is_escaped= (*ptr == '\\');
if (*ptr == '[') /* Group name */ if (*ptr == '[') /* Group name */
{ {
found_group=1; found_group=1;
@@ -309,6 +315,13 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
for (value++ ; isspace(*value); value++) ; for (value++ ; isspace(*value); value++) ;
value_end=strend(value); value_end=strend(value);
for ( ; isspace(value_end[-1]) ; value_end--) ; 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 */ if (value_end < value) /* Empty string */
value_end=value; value_end=value;
if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3 + if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3 +

View File

@@ -27,6 +27,42 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "my_test.h" #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) static int test_bug20023(MYSQL *mysql)
{ {
int sql_big_selects_orig; int sql_big_selects_orig;
@@ -602,6 +638,7 @@ int test_connection_timeout(MYSQL *my)
} }
struct my_tests_st my_tests[] = { 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_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_bug31669", test_bug31669, 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}, {"test_bug33831", test_bug33831, TEST_CONNECTION_NEW, 0, NULL, NULL},