From 1f4f86d5ce2c4ba8d3b8a9b4ae2387f3c4ab7ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 14 Jul 2021 18:49:26 +0200 Subject: [PATCH] Added mysql variable to enable unsupported query 'LOAD DATA LOCAL INFILE' issuing warning message #3500 --- include/MySQL_Thread.h | 1 + include/proxysql_structs.h | 2 ++ lib/MySQL_Session.cpp | 25 ++++++++++++++++--------- lib/MySQL_Thread.cpp | 4 ++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index a3dd6aef7..4afa51740 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -535,6 +535,7 @@ class MySQL_Threads_Handler bool client_session_track_gtid; bool enable_client_deprecate_eof; bool enable_server_deprecate_eof; + bool enable_load_data_local_infile; bool log_mysql_warnings_enabled; } variables; struct { diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index ca53c1319..57a47eb81 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -798,6 +798,7 @@ __thread int mysql_thread___query_digests_grouping_limit; __thread bool mysql_thread___enable_client_deprecate_eof; __thread bool mysql_thread___enable_server_deprecate_eof; __thread bool mysql_thread___log_mysql_warnings_enabled; +__thread bool mysql_thread___enable_load_data_local_infile; /* variables used for Query Cache */ __thread int mysql_thread___query_cache_size_MB; @@ -949,6 +950,7 @@ extern __thread int mysql_thread___query_digests_grouping_limit; extern __thread bool mysql_thread___enable_client_deprecate_eof; extern __thread bool mysql_thread___enable_server_deprecate_eof; extern __thread bool mysql_thread___log_mysql_warnings_enabled; +extern __thread bool mysql_thread___enable_load_data_local_infile; /* variables used for Query Cache */ extern __thread int mysql_thread___query_cache_size_MB; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 7f0151901..e4be62296 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1333,16 +1333,23 @@ bool MySQL_Session::handler_special_queries(PtrSize_t *pkt) { return true; } // 'LOAD DATA LOCAL INFILE' is unsupported. We report an specific error to inform clients about this fact. For more context see #833. - if ( (pkt->size >= 22 + 5) && (strncasecmp((char *)"LOAD DATA LOCAL INFILE",(char *)pkt->ptr+5, 22)==0) ) { - client_myds->DSS=STATE_QUERY_SENT_NET; - client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,1,1047,(char *)"HY000",(char *)"Unsupported 'LOAD DATA LOCAL INFILE' command",true); - client_myds->DSS=STATE_SLEEP; - status=WAITING_CLIENT_DATA; - if (mirror==false) { - RequestEnd(NULL); + + if (mysql_thread___enable_load_data_local_infile == false) { + if ( (pkt->size >= 22 + 5) && (strncasecmp((char *)"LOAD DATA LOCAL INFILE",(char *)pkt->ptr+5, 22)==0) ) { + client_myds->DSS=STATE_QUERY_SENT_NET; + client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,1,1047,(char *)"HY000",(char *)"Unsupported 'LOAD DATA LOCAL INFILE' command",true); + client_myds->DSS=STATE_SLEEP; + status=WAITING_CLIENT_DATA; + if (mirror==false) { + RequestEnd(NULL); + } + l_free(pkt->size,pkt->ptr); + return true; } - l_free(pkt->size,pkt->ptr); - return true; + } else { + proxy_warning( + "Command 'LOAD DATA LOCAL INFILE' refers to file in ProxySQL instance, NOT on client side!\n" + ); } return false; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 1c29278ba..946942294 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -421,6 +421,7 @@ static char * mysql_thread_variables_names[]= { (char *)"connect_timeout_server_max", (char *)"enable_client_deprecate_eof", (char *)"enable_server_deprecate_eof", + (char *)"enable_load_data_local_infile", (char *)"eventslog_filename", (char *)"eventslog_filesize", (char *)"eventslog_default_log", @@ -1158,6 +1159,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.query_digests_grouping_limit = 3; variables.enable_client_deprecate_eof=true; variables.enable_server_deprecate_eof=true; + variables.enable_load_data_local_infile=false; variables.log_mysql_warnings_enabled=false; // status variables status_variables.mirror_sessions_current=0; @@ -1970,6 +1972,7 @@ char ** MySQL_Threads_Handler::get_variables_list() { VariablesPointers_bool["default_reconnect"] = make_tuple(&variables.default_reconnect, false); VariablesPointers_bool["enable_client_deprecate_eof"] = make_tuple(&variables.enable_client_deprecate_eof, false); VariablesPointers_bool["enable_server_deprecate_eof"] = make_tuple(&variables.enable_server_deprecate_eof, false); + VariablesPointers_bool["enable_load_data_local_infile"] = make_tuple(&variables.enable_load_data_local_infile, false); VariablesPointers_bool["enforce_autocommit_on_reads"] = make_tuple(&variables.enforce_autocommit_on_reads, false); VariablesPointers_bool["firewall_whitelist_enabled"] = make_tuple(&variables.firewall_whitelist_enabled, false); VariablesPointers_bool["kill_backend_connection_when_disconnect"] = make_tuple(&variables.kill_backend_connection_when_disconnect, false); @@ -3655,6 +3658,7 @@ void MySQL_Thread::refresh_variables() { mysql_thread___default_reconnect=(bool)GloMTH->get_variable_int((char *)"default_reconnect"); mysql_thread___enable_client_deprecate_eof=(bool)GloMTH->get_variable_int((char *)"enable_client_deprecate_eof"); mysql_thread___enable_server_deprecate_eof=(bool)GloMTH->get_variable_int((char *)"enable_server_deprecate_eof"); + mysql_thread___enable_load_data_local_infile=(bool)GloMTH->get_variable_int((char *)"enable_load_data_local_infile"); mysql_thread___log_mysql_warnings_enabled=(bool)GloMTH->get_variable_int((char *)"log_mysql_warnings_enabled"); #ifdef DEBUG mysql_thread___session_debug=(bool)GloMTH->get_variable_int((char *)"session_debug");