diff --git a/libmariadb/my_loaddata.c b/libmariadb/my_loaddata.c index 3698ad95..1f62631d 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/my_loaddata.c @@ -234,6 +234,14 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) DBUG_ENTER("mysql_handle_local_infile"); + /* check if all callback functions exist */ + if (!conn->options.local_infile_init || !conn->options.local_infile_end || + !conn->options.local_infile_read || !conn->options.local_infile_error) + { + conn->options.local_infile_userdata= conn; + mysql_set_local_infile_default(conn); + } + if (!(conn->options.client_flag & CLIENT_LOCAL_FILES)) { my_set_error(conn, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, "Load data local infile forbidden"); /* write empty packet to server */ @@ -242,13 +250,6 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) goto infile_error; } - /* check if all callback functions exist */ - if (!conn->options.local_infile_init || !conn->options.local_infile_end || - !conn->options.local_infile_read || !conn->options.local_infile_error) - { - conn->options.local_infile_userdata= conn; - mysql_set_local_infile_default(conn); - } /* allocate buffer for reading data */ buf = (uchar *)my_malloc(buflen, MYF(0)); diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index 9c58d412..f8cae7c0 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -30,12 +30,35 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "my_test.h" #include "ma_common.h" +static int test_conc74(MYSQL *my) +{ + int rc; + MYSQL *mysql; + + mysql= mysql_init(NULL); + + + mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS a"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE a (a varchar(200))"); + check_mysql_rc(rc, mysql); + + mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; + + rc= mysql_query(mysql, "load data local infile './nonexistingfile.csv' into table a (`a`)"); + FAIL_IF(!rc, "Error expected"); + + mysql_close(mysql); + return OK; +} + + static int test_conc71(MYSQL *my) { int rc; - MYSQL_RES *res; - MYSQL_ROW row; - char *query; MYSQL *mysql; /* uncomment if you want to test manually */ @@ -680,6 +703,7 @@ static int test_compressed(MYSQL *my) } struct my_tests_st my_tests[] = { + {"test_conc74", test_conc74, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc71", test_conc71, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc70", test_conc70, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc68", test_conc68, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},