diff options
Diffstat (limited to 'plugin')
23 files changed, 497 insertions, 174 deletions
diff --git a/plugin/auth_gssapi/mysql-test/auth_gssapi/groups.result b/plugin/auth_gssapi/mysql-test/auth_gssapi/groups.result new file mode 100644 index 00000000000..10b3eb3e9d6 --- /dev/null +++ b/plugin/auth_gssapi/mysql-test/auth_gssapi/groups.result @@ -0,0 +1,44 @@ +INSTALL SONAME 'auth_gssapi'; +Warnings: +Note 1105 SSPI: using principal name 'localhost', mech 'Negotiate' +CREATE USER 'nosuchgroup' IDENTIFIED WITH gssapi AS 'GROUP:nosuchgroup'; +connect(localhost,nosuchuser,,test,MASTER_MYPORT,MASTER_MYSOCK); +connect con1,localhost,nosuchuser,,; +ERROR 28000: Access denied for user 'nosuchuser'@'localhost' (using password: NO) +DROP USER nosuchgroup; +CREATE USER 'nullsid' IDENTIFIED WITH gssapi AS 'SID:S-1-0-0'; +connect(localhost,nullsid,,test,MASTER_MYPORT,MASTER_MYSOCK); +connect con1,localhost,nullsid,,; +ERROR 28000: Access denied for user 'nullsid'@'localhost' (using password: NO) +DROP USER nullsid; +CREATE USER 'anonymous' IDENTIFIED WITH gssapi AS 'SID:AN'; +connect(localhost,anonymous,,test,MASTER_MYPORT,MASTER_MYSOCK); +connect con1,localhost,anonymous,,; +ERROR 28000: Access denied for user 'anonymous'@'localhost' (using password: NO) +DROP USER anonymous; +CREATE USER 'group_everyone' IDENTIFIED WITH gssapi AS 'GROUP:Everyone'; +connect con1,localhost,group_everyone,,; +disconnect con1; +connection default; +DROP USER group_everyone; +CREATE USER 'sid_wd' IDENTIFIED WITH gssapi AS 'SID:WD'; +connect con1,localhost,sid_wd,,; +disconnect con1; +connection default; +DROP USER sid_wd; +CREATE USER 'S_1_1_0' IDENTIFIED WITH gssapi AS 'SID:S-1-1-0'; +connect con1,localhost,S_1_1_0,,; +disconnect con1; +connection default; +DROP USER S_1_1_0; +CREATE USER 'me_short' IDENTIFIED WITH gssapi AS 'GROUP:GSSAPI_SHORTNAME'; +connect con1,localhost,me_short,,; +disconnect con1; +connection default; +DROP USER me_short; +CREATE USER 'me_sid' IDENTIFIED WITH gssapi AS 'SID:MY-SID'; +connect con1,localhost,me_sid,,; +disconnect con1; +connection default; +DROP USER me_sid; +UNINSTALL SONAME 'auth_gssapi'; diff --git a/plugin/auth_gssapi/mysql-test/auth_gssapi/groups.test b/plugin/auth_gssapi/mysql-test/auth_gssapi/groups.test new file mode 100644 index 00000000000..1c72ad9cc23 --- /dev/null +++ b/plugin/auth_gssapi/mysql-test/auth_gssapi/groups.test @@ -0,0 +1,73 @@ +source include/windows.inc; +--replace_regex /name '[^']+'/name 'localhost'/ +INSTALL SONAME 'auth_gssapi'; + + +# Invalid group name +CREATE USER 'nosuchgroup' IDENTIFIED WITH gssapi AS 'GROUP:nosuchgroup'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +error ER_ACCESS_DENIED_ERROR; +connect (con1,localhost,nosuchuser,,); +DROP USER nosuchgroup; + +# Group with no members, NULL SID +CREATE USER 'nullsid' IDENTIFIED WITH gssapi AS 'SID:S-1-0-0'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +error ER_ACCESS_DENIED_ERROR; +connect (con1,localhost,nullsid,,); +DROP USER nullsid; + + +# Anonymous +CREATE USER 'anonymous' IDENTIFIED WITH gssapi AS 'SID:AN'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +error ER_ACCESS_DENIED_ERROR; +connect (con1,localhost,anonymous,,); +DROP USER anonymous; + + +# Positive tests + +# Everyone group +CREATE USER 'group_everyone' IDENTIFIED WITH gssapi AS 'GROUP:Everyone'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +connect (con1,localhost,group_everyone,,); +disconnect con1; +connection default; +DROP USER group_everyone; + +# Everyone AS well-known SID name +CREATE USER 'sid_wd' IDENTIFIED WITH gssapi AS 'SID:WD'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +connect (con1,localhost,sid_wd,,); +disconnect con1; +connection default; +DROP USER sid_wd; + +# Everyone AS SID S-1-1-0 +CREATE USER 'S_1_1_0' IDENTIFIED WITH gssapi AS 'SID:S-1-1-0'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +connect (con1,localhost,S_1_1_0,,); +disconnect con1; +connection default; +DROP USER S_1_1_0; + +replace_result $GSSAPI_SHORTNAME GSSAPI_SHORTNAME; +eval CREATE USER 'me_short' IDENTIFIED WITH gssapi AS 'GROUP:$GSSAPI_SHORTNAME'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +connect (con1,localhost,me_short,,); +disconnect con1; +connection default; +DROP USER me_short; + + +replace_result $SID MY-SID; +eval CREATE USER 'me_sid' IDENTIFIED WITH gssapi AS 'SID:$SID'; +replace_result $MASTER_MYSOCK MASTER_MYSOCK $MASTER_MYPORT MASTER_MYPORT; +connect (con1,localhost,me_sid,,); +disconnect con1; +connection default; +DROP USER me_sid; + + +UNINSTALL SONAME 'auth_gssapi';
\ No newline at end of file diff --git a/plugin/auth_gssapi/mysql-test/auth_gssapi/suite.pm b/plugin/auth_gssapi/mysql-test/auth_gssapi/suite.pm index aa225536a1e..e77ba05cb5c 100644 --- a/plugin/auth_gssapi/mysql-test/auth_gssapi/suite.pm +++ b/plugin/auth_gssapi/mysql-test/auth_gssapi/suite.pm @@ -14,6 +14,9 @@ if ($^O eq "MSWin32") $fullname =~ s/\\/\\\\/; # SQL escaping for backslash $ENV{'GSSAPI_FULLNAME'} = $fullname; $ENV{'GSSAPI_SHORTNAME'} = $ENV{'USERNAME'}; + chomp(my $sid = `powershell -Command "([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value"`); + $ENV{'SID'} = $sid; + } else { diff --git a/plugin/auth_gssapi/server_plugin.cc b/plugin/auth_gssapi/server_plugin.cc index 4fdad2de4b8..eeca4607ece 100644 --- a/plugin/auth_gssapi/server_plugin.cc +++ b/plugin/auth_gssapi/server_plugin.cc @@ -32,11 +32,7 @@ GSSAPI authentication plugin, server side */ -#ifdef _WIN32 -typedef unsigned __int64 my_ulonglong; -#else typedef unsigned long long my_ulonglong; -#endif #include <stdlib.h> #include <mysqld_error.h> diff --git a/plugin/auth_gssapi/sspi_server.cc b/plugin/auth_gssapi/sspi_server.cc index 44aa5051472..4a1958089ef 100644 --- a/plugin/auth_gssapi/sspi_server.cc +++ b/plugin/auth_gssapi/sspi_server.cc @@ -31,7 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "server_plugin.h" #include <mysql/plugin_auth.h> #include <mysqld_error.h> - +#include <sddl.h> /* This sends the error to the client */ static void log_error(SECURITY_STATUS err, const char *msg) @@ -140,32 +140,140 @@ static int get_client_name_from_context(CtxtHandle *ctxt, } -int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) +/* + Check if username from SSPI context matches the name requested + in MYSQL_SERVER_AUTH_INFO + + There are 2 ways to specify SSPI username + username, of auth_string. + + if auth_string is used, we compare full name (i.e , with user+domain) + if not, we match just the user name. +*/ +static bool check_username_match(CtxtHandle *ctxt, + MYSQL_SERVER_AUTH_INFO *auth_info) { - int ret; - SECURITY_STATUS sspi_ret; - ULONG attribs = 0; - TimeStamp lifetime; - CredHandle cred; - CtxtHandle ctxt; + char client_name[MYSQL_USERNAME_LENGTH + 1]; + const char *user= 0; + int compare_full_name;; + if (auth_info->auth_string_length > 0) + { + compare_full_name= 1; + user= auth_info->auth_string; + } + else + { + compare_full_name= 0; + user= auth_info->user_name; + } + if (get_client_name_from_context(ctxt, client_name, MYSQL_USERNAME_LENGTH, + compare_full_name) != CR_OK) + { + return false; + } + + /* Always compare case-insensitive on Windows. */ + if (_stricmp(client_name, user)) + { + my_printf_error(ER_ACCESS_DENIED_ERROR, + "GSSAPI name mismatch, requested '%s', actual name '%s'", 0, user, + client_name); + return false; + } + return true; +} + + +/* + Checks the security token extracted from SSPI context + for membership in specfied group. + + @param ctxt - SSPI context + @param group_name - group name to check membership against + NOTE: this can also be a user's name + + @param use_sid - whether name is SID + @last_error - will be set, if the function returns false, and + some of the API's have failed. + @failing_api - name of the API that has failed(for error logging) +*/ +static bool check_group_match(CtxtHandle *ctxt, const char *name, + bool name_is_sid) +{ + BOOL is_member= FALSE; + bool is_impersonating= false; + bool free_sid= false; + PSID sid= 0; + + +#define FAIL(msg) \ + do \ + { \ + log_error(GetLastError(), msg); \ + goto cleanup; \ + } while (0) + + /* Get the group SID.*/ + if (name_is_sid) + { + if (!ConvertStringSidToSidA(name, &sid)) + FAIL("ConvertStringSidToSid"); + free_sid= true; + } + else + { + /* Get the SID of the specified group via LookupAccountName().*/ + char sid_buf[SECURITY_MAX_SID_SIZE]; + char domain[256]; + DWORD sid_size= sizeof(sid_buf); + DWORD domain_size= sizeof(domain); + + SID_NAME_USE sid_name_use; + sid= (PSID) sid_buf; + + if (!LookupAccountName(0, name, sid, &sid_size, domain, + &domain_size, &sid_name_use)) + { + FAIL("LookupAccountName"); + } + } + + /* Impersonate, to check group membership */ + if (ImpersonateSecurityContext(ctxt)) + FAIL("ImpersonateSecurityContext"); + is_impersonating= true; + if (!CheckTokenMembership(GetCurrentThreadToken(), sid, &is_member)) + FAIL("CheckTokenMembership"); + +cleanup: + if (is_impersonating) + RevertSecurityContext(ctxt); + if (free_sid) + LocalFree(sid); + return is_member; +} + +static SECURITY_STATUS sspi_get_context(MYSQL_PLUGIN_VIO *vio, + CtxtHandle *ctxt, CredHandle *cred) +{ + SECURITY_STATUS sspi_ret= SEC_E_OK; + ULONG attribs= 0; + TimeStamp lifetime; SecBufferDesc inbuf_desc; SecBuffer inbuf; SecBufferDesc outbuf_desc; SecBuffer outbuf; void* out= NULL; - char client_name[MYSQL_USERNAME_LENGTH + 1]; - const char *user= 0; - int compare_full_name; - ret= CR_ERROR; - SecInvalidateHandle(&cred); - SecInvalidateHandle(&ctxt); + SecInvalidateHandle(cred); + SecInvalidateHandle(ctxt); out= malloc(SSPI_MAX_TOKEN_SIZE); if (!out) { log_error(SEC_E_OK, "memory allocation failed"); + sspi_ret= SEC_E_INSUFFICIENT_MEMORY; goto cleanup; } sspi_ret= AcquireCredentialsHandle( @@ -176,7 +284,7 @@ int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) NULL, NULL, NULL, - &cred, + cred, &lifetime); if (SEC_ERROR(sspi_ret)) @@ -209,28 +317,15 @@ int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) log_error(SEC_E_OK, "communication error(read)"); goto cleanup; } - if (!user) - { - if (auth_info->auth_string_length > 0) - { - compare_full_name= 1; - user= auth_info->auth_string; - } - else - { - compare_full_name= 0; - user= auth_info->user_name; - } - } inbuf.cbBuffer= len; outbuf.cbBuffer= SSPI_MAX_TOKEN_SIZE; sspi_ret= AcceptSecurityContext( - &cred, - SecIsValidHandle(&ctxt) ? &ctxt : NULL, + cred, + SecIsValidHandle(ctxt) ? ctxt : NULL, &inbuf_desc, attribs, SECURITY_NATIVE_DREP, - &ctxt, + ctxt, &outbuf_desc, &attribs, &lifetime); @@ -256,18 +351,57 @@ int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) } } while (sspi_ret == SEC_I_CONTINUE_NEEDED); - /* Authentication done, now extract and compare user name. */ - ret= get_client_name_from_context(&ctxt, client_name, MYSQL_USERNAME_LENGTH, compare_full_name); - if (ret != CR_OK) +cleanup: + free(out); + return sspi_ret; +} + + +int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) +{ + int ret= CR_ERROR; + const char* group = 0; + bool use_sid = 0; + + CtxtHandle ctxt; + CredHandle cred; + if (sspi_get_context(vio, &ctxt, &cred) != SEC_E_OK) goto cleanup; - /* Always compare case-insensitive on Windows. */ - ret= _stricmp(client_name, user) == 0 ? CR_OK : CR_ERROR; - if (ret != CR_OK) + + /* + Authentication done, now test user name, or group + membership. + First, find out if matching group was requested. + */ + static struct { - my_printf_error(ER_ACCESS_DENIED_ERROR, - "GSSAPI name mismatch, requested '%s', actual name '%s'", - 0, user, client_name); + const char *str; + size_t len; + bool sid; + } prefixes[]= {{"GROUP:", sizeof("GROUP:") - 1, false}, + {"SID:", sizeof("SID:") - 1, true}}; + group= 0; + for (auto &prefix : prefixes) + { + if (auth_info->auth_string_length >= prefix.len && + !strncmp(auth_info->auth_string, prefix.str, prefix.len)) + { + group= auth_info->auth_string + prefix.len; + use_sid= prefix.sid; + break; + } + } + + if (group) + { + /* Test group membership.*/ + ret= check_group_match(&ctxt, group, use_sid) ? CR_OK : CR_ERROR; + } + else + { + /* Compare username. */ + ret= check_username_match(&ctxt, auth_info) ? CR_OK : CR_ERROR; } cleanup: @@ -277,7 +411,6 @@ cleanup: if (SecIsValidHandle(&cred)) FreeCredentialsHandle(&cred); - free(out); return ret; } diff --git a/plugin/auth_socket/CMakeLists.txt b/plugin/auth_socket/CMakeLists.txt index a3f42d416a7..83e0b86d8cb 100644 --- a/plugin/auth_socket/CMakeLists.txt +++ b/plugin/auth_socket/CMakeLists.txt @@ -14,6 +14,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA +IF(WIN32) + RETURN() +ENDIF() + CHECK_CXX_SOURCE_COMPILES( "#define _GNU_SOURCE #include <sys/socket.h> @@ -57,6 +61,21 @@ IF (HAVE_XUCRED) SET(ok 1) ELSE() +# NetBSD, is that you? +CHECK_CXX_SOURCE_COMPILES( +"#include <sys/un.h> +#include <sys/socket.h> +int main() { + struct unpcbid unp; + socklen_t unpl = sizeof(unp); + getsockopt(0, 0, LOCAL_PEEREID, &unp, &unpl); + }" HAVE_UNPCBID) + +IF (HAVE_UNPCBID) + ADD_DEFINITIONS(-DHAVE_UNPCBID) + SET(ok 1) +ELSE() + # illumos, is that you? CHECK_CXX_SOURCE_COMPILES( "#include <ucred.h> @@ -104,6 +123,7 @@ ENDIF() ENDIF() ENDIF() ENDIF() +ENDIF() IF(ok) MYSQL_ADD_PLUGIN(auth_socket auth_socket.c DEFAULT) diff --git a/plugin/auth_socket/auth_socket.c b/plugin/auth_socket/auth_socket.c index c20defed872..3a933b6ab62 100644 --- a/plugin/auth_socket/auth_socket.c +++ b/plugin/auth_socket/auth_socket.c @@ -47,6 +47,13 @@ #define uid cr_uid #define ucred xucred +#elif defined HAVE_UNPCBID +#include <sys/un.h> +#define level 0 +#define SO_PEERCRED LOCAL_PEEREID +#define uid unp_euid +#define ucred unpcbid + #elif defined HAVE_GETPEERUCRED #include <ucred.h> diff --git a/plugin/disks/mysql-test/disks/disks.result b/plugin/disks/mysql-test/disks/disks.result index 319e1eac10f..eb78d4073df 100644 --- a/plugin/disks/mysql-test/disks/disks.result +++ b/plugin/disks/mysql-test/disks/disks.result @@ -6,7 +6,7 @@ DISKS CREATE TEMPORARY TABLE `DISKS` ( `Total` bigint(32) NOT NULL, `Used` bigint(32) NOT NULL, `Available` bigint(32) NOT NULL -) ENGINE=MEMORY DEFAULT CHARSET=utf8 +) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 select sum(Total) > sum(Available), sum(Total)>sum(Used) from information_schema.disks; sum(Total) > sum(Available) sum(Total)>sum(Used) 1 1 diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index 73b1bc67e79..1aac71b132a 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -183,15 +183,15 @@ static void send_report(const char *when) str.length(0); str.append(STRING_WITH_LEN("FEEDBACK_SERVER_UID")); str.append('\t'); - str.append(server_uid_buf); + str.append(server_uid_buf, sizeof(server_uid_buf)-1); str.append('\n'); str.append(STRING_WITH_LEN("FEEDBACK_WHEN")); str.append('\t'); - str.append(when); + str.append(when, strlen(when)); str.append('\n'); str.append(STRING_WITH_LEN("FEEDBACK_USER_INFO")); str.append('\t'); - str.append(user_info); + str.append(user_info, strlen(user_info)); str.append('\n'); str.append('\n'); } diff --git a/plugin/feedback/utils.cc b/plugin/feedback/utils.cc index e362446204f..bbbd5850089 100644 --- a/plugin/feedback/utils.cc +++ b/plugin/feedback/utils.cc @@ -246,7 +246,7 @@ int my_getncpus() { #ifdef _SC_NPROCESSORS_ONLN return sysconf(_SC_NPROCESSORS_ONLN); -#elif defined(__WIN__) +#elif defined(_WIN32) SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; diff --git a/plugin/func_test/plugin.cc b/plugin/func_test/plugin.cc index 811189773f1..f59ee82388c 100644 --- a/plugin/func_test/plugin.cc +++ b/plugin/func_test/plugin.cc @@ -24,20 +24,25 @@ class Item_func_sysconst_test :public Item_func_sysconst { public: Item_func_sysconst_test(THD *thd): Item_func_sysconst(thd) {} - String *val_str(String *str) + String *val_str(String *str) override { null_value= str->copy(STRING_WITH_LEN("sysconst_test"), system_charset_info); return null_value ? NULL : str; } - bool fix_length_and_dec() + bool fix_length_and_dec() override { max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; - maybe_null= true; + set_maybe_null(); return false; } - const char *func_name() const { return "sysconst_test"; } - const char *fully_qualified_func_name() const { return "sysconst_test()"; } - Item *get_copy(THD *thd) + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("sysconst_test") }; + return name; + } + const char *fully_qualified_func_name() const override + { return "sysconst_test()"; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_sysconst_test>(thd, this); } }; diff --git a/plugin/qc_info/qc_info.cc b/plugin/qc_info/qc_info.cc index e97f547550f..a46e2d9fbf2 100644 --- a/plugin/qc_info/qc_info.cc +++ b/plugin/qc_info/qc_info.cc @@ -185,23 +185,21 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables, cs_client= get_charset(flags.character_set_client_num, MYF(MY_WME)); if (likely(cs_client)) table->field[COLUMN_CHARACTER_SET_CLIENT]-> - store(cs_client->csname, strlen(cs_client->csname), scs); + store(&cs_client->cs_name, scs); else table->field[COLUMN_CHARACTER_SET_CLIENT]-> store(STRING_WITH_LEN(unknown), scs); cs_result= get_charset(flags.character_set_results_num, MYF(MY_WME)); if (likely(cs_result)) - table->field[COLUMN_CHARACTER_SET_RESULT]-> - store(cs_result->csname, strlen(cs_result->csname), scs); + table->field[COLUMN_CHARACTER_SET_RESULT]->store(&cs_result->cs_name, scs); else table->field[COLUMN_CHARACTER_SET_RESULT]-> store(STRING_WITH_LEN(unknown), scs); collation= get_charset(flags.collation_connection_num, MYF(MY_WME)); if (likely(collation)) - table->field[COLUMN_COLLATION]-> - store(collation->name, strlen(collation->name), scs); + table->field[COLUMN_COLLATION]-> store(&collation->coll_name, scs); else table->field[COLUMN_COLLATION]-> store(STRING_WITH_LEN(unknown), scs); diff --git a/plugin/query_response_time/mysql-test/query_response_time/basic.result b/plugin/query_response_time/mysql-test/query_response_time/basic.result index c8dd4f89f74..8f25804e253 100644 --- a/plugin/query_response_time/mysql-test/query_response_time/basic.result +++ b/plugin/query_response_time/mysql-test/query_response_time/basic.result @@ -9,7 +9,7 @@ QUERY_RESPONSE_TIME CREATE TEMPORARY TABLE `QUERY_RESPONSE_TIME` ( `TIME` varchar(14) NOT NULL, `COUNT` int(11) unsigned NOT NULL, `TOTAL` varchar(14) NOT NULL -) ENGINE=MEMORY DEFAULT CHARSET=utf8 +) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'query_response_time%';; PLUGIN_NAME QUERY_RESPONSE_TIME PLUGIN_VERSION 1.0 diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 4a54e0e8f4b..7c022f83aeb 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -142,6 +142,13 @@ static int loc_file_errno; #define logger_init_mutexts loc_logger_init_mutexts #define logger_time_to_rotate loc_logger_time_to_rotate +#ifndef HOSTNAME_LENGTH +#define HOSTNAME_LENGTH 255 +#endif +#ifndef USERNAME_CHAR_LENGTH +#define USERNAME_CHAR_LENGTH 128 +#endif + static size_t loc_write(File Filedes, const uchar *Buffer, size_t Count) { @@ -210,7 +217,7 @@ static int loc_rename(const char *from, const char *to) { int error = 0; -#if defined(__WIN__) +#if defined(_WIN32) if (!MoveFileEx(from, to, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) { @@ -279,6 +286,7 @@ static my_off_t loc_tell(File fd) extern MYSQL_PLUGIN_IMPORT char server_version[]; static const char *serv_ver= NULL; +const char *(*thd_priv_host_ptr)(MYSQL_THD thd, size_t *length); static int started_mysql= 0; static int mysql_57_started= 0; static int debug_server_started= 0; @@ -303,7 +311,7 @@ static char incl_user_buffer[1024]; static char excl_user_buffer[1024]; static unsigned int query_log_limit= 0; -static char servhost[256]; +static char servhost[HOSTNAME_LENGTH+1]; static uint servhost_len; static char *syslog_ident; static char syslog_ident_buffer[128]= "mysql-server_auditing"; @@ -315,9 +323,9 @@ struct connection_info unsigned long long query_id; char db[256]; int db_length; - char user[64]; + char user[USERNAME_CHAR_LENGTH+1]; int user_length; - char host[64]; + char host[HOSTNAME_LENGTH+1]; int host_length; char ip[64]; int ip_length; @@ -326,9 +334,9 @@ struct connection_info char query_buffer[1024]; time_t query_time; int log_always; - char proxy[64]; + char proxy[USERNAME_CHAR_LENGTH+1]; int proxy_length; - char proxy_host[64]; + char proxy_host[HOSTNAME_LENGTH+1]; int proxy_host_length; }; @@ -1026,9 +1034,9 @@ static int get_user_host(const char *uh_line, unsigned int uh_len, return 0; } -#if defined(__WIN__) && !defined(S_ISDIR) +#if defined(_WIN32) && !defined(S_ISDIR) #define S_ISDIR(x) ((x) & _S_IFDIR) -#endif /*__WIN__ && !S_ISDIR*/ +#endif /*_WIN32 && !S_ISDIR*/ static int start_logging() { @@ -1132,10 +1140,10 @@ static void setup_connection_simple(struct connection_info *ci) } -#define MAX_HOSTNAME 61 +#define MAX_HOSTNAME (HOSTNAME_LENGTH + 1) /* len+1 in mysql.user */ #define USERNAME_LENGTH 384 -static void setup_connection_connect(struct connection_info *cn, +static void setup_connection_connect(MYSQL_THD thd,struct connection_info *cn, const struct mysql_event_connection *event) { cn->query_id= 0; @@ -1153,17 +1161,26 @@ static void setup_connection_connect(struct connection_info *cn, cn->header= 0; if (event->proxy_user && event->proxy_user[0]) { - const char *priv_host= event->proxy_user + - sizeof(char[MAX_HOSTNAME+USERNAME_LENGTH+5]); + const char *priv_host; size_t priv_host_length; - if (mysql_57_started) + if (thd_priv_host_ptr) { - priv_host+= sizeof(size_t); - priv_host_length= *(size_t *) (priv_host + MAX_HOSTNAME); + priv_host= (*thd_priv_host_ptr)(thd, &priv_host_length); } else - priv_host_length= strlen(priv_host); + { + // 5 is "'" around host and user and "@" + priv_host= event->proxy_user + + sizeof(char[MAX_HOSTNAME + USERNAME_LENGTH + 5]); + if (mysql_57_started) + { + priv_host+= sizeof(size_t); + priv_host_length= *(size_t *) (priv_host + MAX_HOSTNAME); + } + else + priv_host_length= strlen(priv_host); + } get_str_n(cn->proxy, &cn->proxy_length, sizeof(cn->proxy), @@ -1957,7 +1974,7 @@ static struct connection_info ci_disconnect_buffer; #define AA_FREE_CONNECTION 1 #define AA_CHANGE_USER 2 -static void update_connection_info(struct connection_info *cn, +static void update_connection_info(MYSQL_THD thd, struct connection_info *cn, unsigned int event_class, const void *ev, int *after_action) { *after_action= 0; @@ -2078,7 +2095,7 @@ static void update_connection_info(struct connection_info *cn, switch (event->event_subclass) { case MYSQL_AUDIT_CONNECTION_CONNECT: - setup_connection_connect(cn, event); + setup_connection_connect(thd, cn, event); break; case MYSQL_AUDIT_CONNECTION_CHANGE_USER: *after_action= AA_CHANGE_USER; @@ -2136,7 +2153,7 @@ void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev) cn= get_loc_info(thd); } - update_connection_info(cn, event_class, ev, &after_action); + update_connection_info(thd, cn, event_class, ev, &after_action); if (!logging) { @@ -2486,6 +2503,8 @@ static int server_audit_init(void *p __attribute__((unused))) } if (!my_hash_init_ptr) return 1; + + thd_priv_host_ptr= dlsym(RTLD_DEFAULT, "thd_priv_host"); } if(!(int_mysql_data_home= find_sym("mysql_data_home"))) diff --git a/plugin/type_inet/item_inetfunc.cc b/plugin/type_inet/item_inetfunc.cc index 50bd82817e0..dcccf762295 100644 --- a/plugin/type_inet/item_inetfunc.cc +++ b/plugin/type_inet/item_inetfunc.cc @@ -24,7 +24,7 @@ longlong Item_func_inet_aton::val_int() { - DBUG_ASSERT(fixed); + DBUG_ASSERT(fixed()); uint byte_result= 0; ulonglong result= 0; // We are ready for 64 bit addresses @@ -85,7 +85,7 @@ err: String* Item_func_inet_ntoa::val_str(String* str) { - DBUG_ASSERT(fixed); + DBUG_ASSERT(fixed()); ulonglong n= (ulonglong) args[0]->val_int(); @@ -145,7 +145,7 @@ String* Item_func_inet_ntoa::val_str(String* str) String *Item_func_inet6_aton::val_str(String *buffer) { - DBUG_ASSERT(fixed); + DBUG_ASSERT(fixed()); Ascii_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); if ((null_value= tmp.is_null())) @@ -176,7 +176,7 @@ String *Item_func_inet6_aton::val_str(String *buffer) String *Item_func_inet6_ntoa::val_str_ascii(String *buffer) { - DBUG_ASSERT(fixed); + DBUG_ASSERT(fixed()); // Binary string argument expected if (unlikely(args[0]->result_type() != STRING_RESULT || @@ -216,7 +216,7 @@ String *Item_func_inet6_ntoa::val_str_ascii(String *buffer) longlong Item_func_is_ipv4::val_int() { - DBUG_ASSERT(fixed); + DBUG_ASSERT(fixed()); String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); return !tmp.is_null() && !Inet4_null(*tmp.string()).is_null(); } @@ -228,7 +228,7 @@ longlong Item_func_is_ipv4::val_int() longlong Item_func_is_ipv6::val_int() { - DBUG_ASSERT(fixed); + DBUG_ASSERT(fixed()); String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); return !tmp.is_null() && !Inet6_null(*tmp.string()).is_null(); } diff --git a/plugin/type_inet/item_inetfunc.h b/plugin/type_inet/item_inetfunc.h index 94255426f68..4acb42d2175 100644 --- a/plugin/type_inet/item_inetfunc.h +++ b/plugin/type_inet/item_inetfunc.h @@ -27,21 +27,25 @@ class Item_func_inet_aton : public Item_longlong_func { - bool check_arguments() const + bool check_arguments() const override { return check_argument_types_can_return_text(0, arg_count); } public: Item_func_inet_aton(THD *thd, Item *a): Item_longlong_func(thd, a) {} - longlong val_int(); - const char *func_name() const { return "inet_aton"; } - bool fix_length_and_dec() + longlong val_int() override; + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("inet_aton") }; + return name; + } + bool fix_length_and_dec() override { decimals= 0; max_length= 21; - maybe_null= 1; + set_maybe_null(); unsigned_flag= 1; return FALSE; } - Item *get_copy(THD *thd) + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_inet_aton>(thd, this); } }; @@ -55,16 +59,20 @@ class Item_func_inet_ntoa : public Item_str_func public: Item_func_inet_ntoa(THD *thd, Item *a): Item_str_func(thd, a) { } - String* val_str(String* str); - const char *func_name() const { return "inet_ntoa"; } - bool fix_length_and_dec() + String *val_str(String* str) override; + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("inet_ntoa") }; + return name; + } + bool fix_length_and_dec() override { decimals= 0; fix_length_and_charset(3 * 8 + 7, default_charset()); - maybe_null= 1; + set_maybe_null(); return FALSE; } - Item *get_copy(THD *thd) + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_inet_ntoa>(thd, this); } }; @@ -98,20 +106,22 @@ public: { } public: - virtual const char *func_name() const - { return "inet6_aton"; } - - virtual bool fix_length_and_dec() + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("inet6_aton") }; + return name; + } + bool fix_length_and_dec() override { decimals= 0; fix_length_and_charset(16, &my_charset_bin); - maybe_null= 1; + set_maybe_null(); return FALSE; } - Item *get_copy(THD *thd) + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_inet6_aton>(thd, this); } - String *val_str(String *to); + String *val_str(String *to) override; }; @@ -127,10 +137,13 @@ public: { } public: - virtual const char *func_name() const - { return "inet6_ntoa"; } + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("inet6_ntoa") }; + return name; + } - virtual bool fix_length_and_dec() + bool fix_length_and_dec() override { decimals= 0; @@ -139,11 +152,11 @@ public: // 4 symbols per group fix_length_and_charset(8 * 4 + 7, default_charset()); - maybe_null= 1; + set_maybe_null();; return FALSE; } - String *val_str_ascii(String *to); - Item *get_copy(THD *thd) + String *val_str_ascii(String *to) override; + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_inet6_ntoa>(thd, this); } }; @@ -160,12 +173,15 @@ public: { } public: - virtual const char *func_name() const - { return "is_ipv4"; } - Item *get_copy(THD *thd) + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("is_ipv4") }; + return name; + } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_is_ipv4>(thd, this); } - longlong val_int(); + longlong val_int() override; }; @@ -180,12 +196,15 @@ public: Item_func_inet_bool_base(thd, ip_addr) { } - virtual const char *func_name() const - { return "is_ipv6"; } - Item *get_copy(THD *thd) + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("is_ipv6") }; + return name; + } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_is_ipv6>(thd, this); } - longlong val_int(); + longlong val_int() override; }; @@ -199,11 +218,14 @@ public: inline Item_func_is_ipv4_compat(THD *thd, Item *ip_addr): Item_func_inet_bool_base(thd, ip_addr) { } - virtual const char *func_name() const - { return "is_ipv4_compat"; } - Item *get_copy(THD *thd) + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("is_ipv4_compat") }; + return name; + } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_is_ipv4_compat>(thd, this); } - longlong val_int(); + longlong val_int() override; }; @@ -217,11 +239,14 @@ public: inline Item_func_is_ipv4_mapped(THD *thd, Item *ip_addr): Item_func_inet_bool_base(thd, ip_addr) { } - virtual const char *func_name() const - { return "is_ipv4_mapped"; } - Item *get_copy(THD *thd) + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("is_ipv4_mapped") }; + return name; + } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_is_ipv4_mapped>(thd, this); } - longlong val_int(); + longlong val_int() override; }; #endif // ITEM_INETFUNC_INCLUDED diff --git a/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result b/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result index 7911407b8f7..79356bee6e2 100644 --- a/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result +++ b/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result @@ -42,7 +42,7 @@ CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER INSERT INTO t1 VALUES('::','',''); # Columns(BINARY(16), # CHAR(16) CHARSET latin1 COLLATE latin1_swedish_ci, -# CHAR(16) CHARSET utf8 COLLATE utf8_general_ci) +# CHAR(16) CHARSET utf8mb3 COLLATE utf8mb3_general_ci) DROP TABLE t1; RESET MASTER; RESET MASTER; @@ -51,7 +51,7 @@ CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER INSERT INTO t1 VALUES('::','',''); # Columns(`a` BINARY(16), # `b` CHAR(16) CHARSET latin1 COLLATE latin1_swedish_ci, -# `c` CHAR(16) CHARSET utf8 COLLATE utf8_general_ci) +# `c` CHAR(16) CHARSET utf8mb3 COLLATE utf8mb3_general_ci) DROP TABLE t1; RESET MASTER; SET GLOBAL binlog_row_metadata = DEFAULT; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.result b/plugin/type_inet/mysql-test/type_inet/type_inet6.result index ac16f5c06ce..0ac5f666b86 100644 --- a/plugin/type_inet/mysql-test/type_inet/type_inet6.result +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.result @@ -996,9 +996,9 @@ FROM t1; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( - `c1` varchar(40) CHARACTER SET utf8 DEFAULT NULL, - `c2` varchar(40) CHARACTER SET utf8 DEFAULT NULL, - `c3` varchar(40) CHARACTER SET utf8 DEFAULT NULL + `c1` varchar(40) CHARACTER SET utf8mb3 DEFAULT NULL, + `c2` varchar(40) CHARACTER SET utf8mb3 DEFAULT NULL, + `c3` varchar(40) CHARACTER SET utf8mb3 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; CREATE TABLE t2 AS SELECT diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc index 26be505ac65..10ccca2da75 100644 --- a/plugin/type_inet/sql_type_inet.cc +++ b/plugin/type_inet/sql_type_inet.cc @@ -510,7 +510,7 @@ size_t Inet6::to_string(char *dst, size_t dstsize) const bool Inet6::fix_fields_maybe_null_on_conversion_to_inet6(Item *item) { - if (item->maybe_null) + if (item->maybe_null()) return true; if (item->type_handler() == &type_handler_inet6) return false; @@ -601,9 +601,9 @@ public: DBUG_ASSERT(!tmp->m_null_value); return m_native.cmp(tmp->m_native); } - cmp_item *make_same() override + cmp_item *make_same(THD *thd) override { - return new cmp_item_inet6(); + return new (thd->mem_root) cmp_item_inet6(); } }; @@ -1048,7 +1048,11 @@ public: Item_typecast_inet6 *cast= (Item_typecast_inet6*) item; return args[0]->eq(cast->args[0], binary_cmp); } - const char *func_name() const override { return "cast_as_inet6"; } + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("cast_as_inet6") }; + return name; + } void print(String *str, enum_query_type query_type) override { str->append(STRING_WITH_LEN("cast(")); @@ -1059,7 +1063,7 @@ public: { Type_std_attributes::operator=(Type_std_attributes_inet6()); if (Inet6::fix_fields_maybe_null_on_conversion_to_inet6(args[0])) - maybe_null= true; + set_maybe_null(); return false; } String *val_str(String *to) override @@ -1216,7 +1220,7 @@ public: { StringBufferInet6 tmp; m_value.to_string(&tmp); - str->append("INET6'"); + str->append(STRING_WITH_LEN("INET6'")); str->append(tmp); str->append('\''); } @@ -1393,15 +1397,13 @@ Type_handler_inet6::character_or_binary_string_to_native(THD *thd, Inet6_null tmp(*str); if (tmp.is_null()) thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, - name().ptr(), - ErrConvString(str).ptr()); + name().ptr(), ErrConvString(str).ptr()); return tmp.is_null() || tmp.to_native(to); } bool -Type_handler_inet6::Item_save_in_value(THD *thd, - Item *item, +Type_handler_inet6::Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_STRING; @@ -1417,8 +1419,7 @@ Type_handler_inet6::Item_save_in_value(THD *thd, FROM t1; */ thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, - name().ptr(), - ErrConvString(str).ptr()); + name().ptr(), ErrConvString(str).ptr()); value->m_type= DYN_COL_NULL; return true; } @@ -1443,7 +1444,7 @@ void Type_handler_inet6::make_sort_key_part(uchar *to, Item *item, DBUG_ASSERT(item->type_handler() == this); NativeBufferInet6 tmp; item->val_native_result(current_thd, &tmp); - if (item->maybe_null) + if (item->maybe_null()) { if (item->null_value) { @@ -1466,7 +1467,7 @@ Type_handler_inet6::make_packed_sort_key_part(uchar *to, Item *item, DBUG_ASSERT(item->type_handler() == this); NativeBufferInet6 tmp; item->val_native_result(current_thd, &tmp); - if (item->maybe_null) + if (item->maybe_null()) { if (item->null_value) { diff --git a/plugin/type_inet/sql_type_inet.h b/plugin/type_inet/sql_type_inet.h index c1abb11fc59..109718637c6 100644 --- a/plugin/type_inet/sql_type_inet.h +++ b/plugin/type_inet/sql_type_inet.h @@ -402,19 +402,19 @@ public: bool can_return_time() const override { return false; } bool convert_to_binary_using_val_native() const override { return true; } - uint Item_time_precision(THD *thd, Item *item) const override + decimal_digits_t Item_time_precision(THD *thd, Item *item) const override { return 0; } - uint Item_datetime_precision(THD *thd, Item *item) const override + decimal_digits_t Item_datetime_precision(THD *thd, Item *item) const override { return 0; } - uint Item_decimal_scale(const Item *item) const override + decimal_digits_t Item_decimal_scale(const Item *item) const override { return 0; } - uint Item_decimal_precision(const Item *item) const override + decimal_digits_t Item_decimal_precision(const Item *item) const override { /* This will be needed if we ever allow cast from INET6 to DECIMAL. @@ -429,7 +429,7 @@ public: Returns how many digits a divisor adds into a division result. See Item::divisor_precision_increment() in item.h for more comments. */ - uint Item_divisor_precision_increment(const Item *) const override + decimal_digits_t Item_divisor_precision_increment(const Item *) const override { return 0; } @@ -698,9 +698,9 @@ public: DBUG_ASSERT(b.length() == Inet6::binary_length()); return memcmp(a.ptr(), b.ptr(), Inet6::binary_length()); } - bool set_comparator_func(Arg_comparator *cmp) const override + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override { - return cmp->set_cmp_func_native(); + return cmp->set_cmp_func_native(thd); } bool Item_const_eq(const Item_const *a, const Item_const *b, bool binary_cmp) const override @@ -715,7 +715,7 @@ public: return !na.is_null() && !nb.is_null() && !na.cmp(nb); } bool Item_hybrid_func_fix_attributes(THD *thd, - const char *name, + const LEX_CSTRING &name, Type_handler_hybrid_field_type *h, Type_all_attributes *attr, Item **items, @@ -737,7 +737,7 @@ public: { if (Inet6::fix_fields_maybe_null_on_conversion_to_inet6(items[i])) { - attr->set_maybe_null(true); + attr->set_type_maybe_null(true); break; } } @@ -748,7 +748,7 @@ public: Item **items, uint nitems) const override { - return Item_hybrid_func_fix_attributes(thd, func->func_name(), + return Item_hybrid_func_fix_attributes(thd, func->func_name_cstring(), func, func, items, nitems); } diff --git a/plugin/type_mysql_json/mysql_json.cc b/plugin/type_mysql_json/mysql_json.cc index 4a75cae3909..c28a403a603 100644 --- a/plugin/type_mysql_json/mysql_json.cc +++ b/plugin/type_mysql_json/mysql_json.cc @@ -16,8 +16,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ -#include "mysql_json.h" #include "my_global.h" +#include "mysql_json.h" #include "compat56.h" #include "my_decimal.h" #include "sql_time.h" @@ -169,25 +169,25 @@ static bool append_string_json(String *buffer, const uchar *data, size_t len) const uchar c= *data; switch (c) { case '\\': - buffer->append("\\\\"); + buffer->append(STRING_WITH_LEN("\\\\")); break; case '\n': - buffer->append("\\n"); + buffer->append(STRING_WITH_LEN("\\n")); break; case '\r': - buffer->append("\\r"); + buffer->append(STRING_WITH_LEN("\\r")); break; case '"': - buffer->append("\\\""); + buffer->append(STRING_WITH_LEN("\\\"")); break; case '\b': - buffer->append("\\b"); + buffer->append(STRING_WITH_LEN("\\b")); break; case '\f': - buffer->append("\\f"); + buffer->append(STRING_WITH_LEN("\\f")); break; case '\t': - buffer->append("\\t"); + buffer->append(STRING_WITH_LEN("\\t")); break; default: buffer->append(c); @@ -242,11 +242,11 @@ static bool parse_mysql_scalar(String *buffer, size_t value_json_type, return true; switch (static_cast<JSONB_LITERAL_TYPES>(*data)) { case JSONB_NULL_LITERAL: - return buffer->append("null"); + return buffer->append(STRING_WITH_LEN("null")); case JSONB_TRUE_LITERAL: - return buffer->append("true"); + return buffer->append(STRING_WITH_LEN("true")); case JSONB_FALSE_LITERAL: - return buffer->append("false"); + return buffer->append(STRING_WITH_LEN("false")); default: /* Invalid literal constant, malformed JSON. */ return true; } @@ -326,7 +326,7 @@ static bool parse_mysql_scalar(String *buffer, size_t value_json_type, default: { /* Any other MySQL type is presented as a base64 encoded string. */ - if (buffer->append("\"base64:type") || + if (buffer->append(STRING_WITH_LEN("\"base64:type")) || buffer->append_longlong(field_type) || buffer->append(':')) return true; @@ -455,7 +455,7 @@ static bool parse_array_or_object(String *buffer, const uchar *data, size_t len, /* First print the key. */ if (buffer->append('"') || append_string_json(buffer, data + key_start, key_len) || - buffer->append("\": ")) + buffer->append(STRING_WITH_LEN("\": "))) { return true; } @@ -478,7 +478,7 @@ static bool parse_array_or_object(String *buffer, const uchar *data, size_t len, return true; } - if (i != element_count - 1 && buffer->append(", ")) + if (i != element_count - 1 && buffer->append(STRING_WITH_LEN(", "))) return true; } diff --git a/plugin/user_variables/mysql-test/user_variables/basic.result b/plugin/user_variables/mysql-test/user_variables/basic.result index e86205dc330..d0841d212ef 100644 --- a/plugin/user_variables/mysql-test/user_variables/basic.result +++ b/plugin/user_variables/mysql-test/user_variables/basic.result @@ -15,7 +15,7 @@ user_variables CREATE TEMPORARY TABLE `user_variables` ( `VARIABLE_VALUE` varchar(2048), `VARIABLE_TYPE` varchar(64) NOT NULL, `CHARACTER_SET_NAME` varchar(32) -) ENGINE=MEMORY DEFAULT CHARSET=utf8 +) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 FLUSH USER_VARIABLES; SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; COUNT(*) @@ -44,7 +44,7 @@ null_var NULL VARCHAR binary str_var Value of string variable VARCHAR latin1 time_var 2016-02-25 VARCHAR latin1 uint_var 2 INT UNSIGNED latin1 -utf8str_var UTF8 string value VARCHAR utf8 +utf8str_var UTF8 string value VARCHAR utf8mb3 SHOW USER_VARIABLES; Variable_name Value Value of variable with empty name diff --git a/plugin/user_variables/user_variables.cc b/plugin/user_variables/user_variables.cc index f820e4ad890..fe87e17f4ee 100644 --- a/plugin/user_variables/user_variables.cc +++ b/plugin/user_variables/user_variables.cc @@ -86,8 +86,7 @@ static int user_variables_fill(THD *thd, TABLE_LIST *tables, COND *cond) if (var->charset()) { - field[3]->store(var->charset()->csname, strlen(var->charset()->csname), - system_charset_info); + field[3]->store(&var->charset()->cs_name, system_charset_info); field[3]->set_notnull(); } else |