You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
CONC-622: Fix double free() if asnyc connect failed
If mysql_real_connect_start/cont failed, we need to set async->pvio to zero after calling ma_pvio_close to avoid double free() in mysql_close.
This commit is contained in:
@@ -1727,6 +1727,14 @@ restart:
|
|||||||
if (ma_pvio_connect(pvio, &cinfo) != 0)
|
if (ma_pvio_connect(pvio, &cinfo) != 0)
|
||||||
{
|
{
|
||||||
ma_pvio_close(pvio);
|
ma_pvio_close(pvio);
|
||||||
|
if (mysql->options.extension && mysql->options.extension->async_context &&
|
||||||
|
mysql->options.extension->async_context->pvio)
|
||||||
|
{
|
||||||
|
/* pvio delegated to mysql->net.pvio by ma_net_init().
|
||||||
|
* invalidate the pvio pointer in the async context */
|
||||||
|
mysql->options.extension->async_context->pvio = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_multi)
|
if (is_multi)
|
||||||
{
|
{
|
||||||
connect_attempts++;
|
connect_attempts++;
|
||||||
|
@@ -248,12 +248,60 @@ static int test_conc129(MYSQL *unused __attribute__((unused)))
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_conc622(MYSQL *my __attribute__((unused)))
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
MYSQL mysql, *ret;
|
||||||
|
int status;
|
||||||
|
uint default_timeout;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (skip_async)
|
||||||
|
return SKIP;
|
||||||
|
|
||||||
|
for (i=0; i < 100; i++)
|
||||||
|
{
|
||||||
|
mysql_init(&mysql);
|
||||||
|
rc= mysql_options(&mysql, MYSQL_OPT_NONBLOCK, 0);
|
||||||
|
check_mysql_rc(rc, (MYSQL *)&mysql);
|
||||||
|
|
||||||
|
/* set timeouts to 300 microseconds */
|
||||||
|
default_timeout= 3;
|
||||||
|
mysql_options(&mysql, MYSQL_OPT_READ_TIMEOUT, &default_timeout);
|
||||||
|
mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, &default_timeout);
|
||||||
|
mysql_options(&mysql, MYSQL_OPT_WRITE_TIMEOUT, &default_timeout);
|
||||||
|
mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "myapp");
|
||||||
|
|
||||||
|
/* Returns 0 when done, else flag for what to wait for when need to block. */
|
||||||
|
status= mysql_real_connect_start(&ret, &mysql, "0.0.0.0", username, password, schema, port, socketname, 0);
|
||||||
|
while (status)
|
||||||
|
{
|
||||||
|
status= wait_for_mysql(&mysql, status);
|
||||||
|
status= mysql_real_connect_cont(&ret, &mysql, status);
|
||||||
|
}
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
status= mysql_close_start(&mysql);
|
||||||
|
while (status)
|
||||||
|
{
|
||||||
|
status= wait_for_mysql(&mysql, status);
|
||||||
|
status= mysql_close_cont(&mysql, status);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
diag("Expected error when connection to host '0.0.0.0'");
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
{"test_async", test_async, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_async", test_async, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"async1", async1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"async1", async1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc131", test_conc131, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
{"test_conc131", test_conc131, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||||
{"test_conc129", test_conc129, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
{"test_conc129", test_conc129, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||||
|
{"test_conc622", test_conc622, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||||
{NULL, NULL, 0, 0, NULL, NULL}
|
{NULL, NULL, 0, 0, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1667,6 +1667,7 @@ static int test_conc312(MYSQL *my)
|
|||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
|
diag("Error: %s", mysql_error(my));
|
||||||
diag("caching_sha256_password not supported");
|
diag("caching_sha256_password not supported");
|
||||||
return SKIP;
|
return SKIP;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user