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

Fixed LOAD DATA LOCAL INFILE crash when specifying a file which doesn't exist

Fixed error message for non existing file (was errno=0)
This commit is contained in:
holzboote@googlemail.com
2013-08-01 15:23:48 +02:00
parent b5db6c127f
commit 5ab0e66191
2 changed files with 29 additions and 6 deletions

View File

@@ -76,9 +76,9 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata)
if (info->fd < 0)
{
info->error_no = my_errno;
my_snprintf((char *)info->error_msg, sizeof(info->error_msg),
"Can't open file '%-.64s'.", filename);
info->error_no = EE_FILENOTFOUND;
EE(EE_FILENOTFOUND), filename, info->error_no);
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -136,11 +136,8 @@ void mysql_local_infile_end(void *ptr)
if (info)
{
if (info->fd)
{
if (info->fd >= 0)
my_close(info->fd, MYF(0));
info->fd= 0;
}
my_free(ptr, MYF(0));
}
DBUG_VOID_RETURN;

View File

@@ -813,6 +813,31 @@ static int test_bug49694(MYSQL *mysql)
return OK;
}
static int test_ldi_path(MYSQL *mysql)
{
int rc;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
check_mysql_rc(rc, mysql);
#ifdef _WIN32
rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'X:/non_existing_path/data.csv' INTO TABLE t1 "
"FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'");
#else
rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE '/non_existing_path/data.csv' INTO TABLE t1 "
"FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'");
#endif
FAIL_IF(rc== 0, "Error expected");
FAIL_IF(mysql_errno(mysql) != 2, "Error code 2 expected");
rc= mysql_query(mysql, "DROP TABLE t1");
check_mysql_rc(rc, mysql);
return OK;
}
struct my_tests_st my_tests[] = {
{"test_bug28075", test_bug28075, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_bug28505", test_bug28505, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
@@ -827,6 +852,7 @@ struct my_tests_st my_tests[] = {
{"test_wl4166_4", test_wl4166_4, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_wl4284_1", test_wl4284_1, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_bug49694", test_bug49694, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_ldi_path", test_ldi_path, TEST_CONNECTION_NEW, 0, NULL, NULL},
{NULL, NULL, 0, 0, NULL, 0}
};