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

Fix for MDEV-12446:

When no default configuration is present, C/C crashed due to double free
in ma_default.c
This commit is contained in:
Georg Richter
2017-03-20 07:29:51 +01:00
parent a1315d2a2d
commit 6bec9204f0
2 changed files with 22 additions and 2 deletions

View File

@@ -93,13 +93,12 @@ my_bool _mariadb_read_options(MYSQL *mysql, const char *config_file,
filename= (char *)malloc(FN_REFLEN + 10);
if (!_mariadb_get_default_file(filename, FN_REFLEN + 10))
{
free(filename);
goto err;
}
}
if (!(file = ma_open(filename, "r", NULL)))
return 1;
goto err;
while (ma_gets(buff,sizeof(buff)-1,file))
{

View File

@@ -1069,7 +1069,28 @@ static int test_reset(MYSQL *mysql)
return OK;
}
static int test_mdev12446(MYSQL *my __attribute__((unused)))
{
/*
if specified file didn't exist, valgrind reported a leak,
if no file was specified and no default file is installed,
C/C crashed due to double free.
*/
MYSQL *mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "file.notfound");
FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
port, socketname, 0), mysql_error(mysql));
mysql_close(mysql);
mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "notfound");
FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
port, socketname, 0), mysql_error(mysql));
mysql_close(mysql);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_mdev12446", test_mdev12446, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_reset", test_reset, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_unix_socket_close", test_unix_socket_close, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_sess_track_db", test_sess_track_db, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},