From: Sergey Vojtovich Date: June 2 2011 8:34am Subject: bzr commit into mysql-5.5 branch (sergey.vojtovich:3416) Bug#12611785 List-Archive: http://lists.mysql.com/commits/138577 X-Bug: 12611785 Message-Id: <201106020834.p528YOsp019566@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6285203959391792235==" --===============6285203959391792235== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #At file:///home/svoj/mysql/server/mysql-5.5-audit/ based on revid:jimmy.yang@stripped 3416 Sergey Vojtovich 2011-06-02 BUG#12611785 - AUDIT INTERFACE STRICT-ALIASING WARNINGS The types mysql_event_general/mysql_event_connection are being cast to the incompatible type mysql_event. The way mysql_event and the other types are designed are prone to strict aliasing violations and can break things depending on how compilers optimizes this code. This patch fixes audit interface, so it confirms to strict- aliasing rules. It introduces incompatible changes to audit interface: - mysql_event type has been removed; - event_class has been removed from mysql_event_generic and mysql_event_connection types; - st_mysql_audit::event_notify() second argument is event_class; - st_mysql_audit::event_notify() third argument is event of type (const void *). "Writing Audit Plugins" section of manual should be updated: http://dev.mysql.com/doc/refman/5.5/en/writing-audit-plugins.html @ include/mysql/plugin_audit.h event_class has been moved out of mysql_event types. @ include/mysql/plugin_audit.h.pp event_class has been moved out of mysql_event types. @ plugin/audit_null/audit_null.c event_class has been moved out of mysql_event types. @ sql/sql_audit.cc event_class has been moved out of mysql_event types. modified: include/mysql/plugin_audit.h include/mysql/plugin_audit.h.pp plugin/audit_null/audit_null.c sql/sql_audit.cc === modified file 'include/mysql/plugin_audit.h' --- a/include/mysql/plugin_audit.h 2010-12-14 14:34:23 +0000 +++ b/include/mysql/plugin_audit.h 2011-06-02 08:34:10 +0000 @@ -24,16 +24,7 @@ #define MYSQL_AUDIT_CLASS_MASK_SIZE 1 -#define MYSQL_AUDIT_INTERFACE_VERSION 0x0200 - -/* - The first word in every event class struct indicates the specific - class of the event. -*/ -struct mysql_event -{ - unsigned int event_class; -}; +#define MYSQL_AUDIT_INTERFACE_VERSION 0x0300 /************************************************************************* @@ -55,7 +46,6 @@ struct mysql_event struct mysql_event_general { - unsigned int event_class; unsigned int event_subclass; int general_error_code; unsigned long general_thread_id; @@ -87,7 +77,6 @@ struct mysql_event_general struct mysql_event_connection { - unsigned int event_class; unsigned int event_subclass; int status; unsigned long thread_id; @@ -118,9 +107,9 @@ struct mysql_event_connection waiting for the next query from the client. event_notify() is invoked whenever an event occurs which is of any - class for which the plugin has interest. The first word of the - mysql_event argument indicates the specific event class and the - remainder of the structure is as required for that class. + class for which the plugin has interest. The second argument + indicates the specific event class and the third argument is data + as required for that class. class_mask is an array of bits used to indicate what event classes that this plugin wants to receive. @@ -130,7 +119,7 @@ struct st_mysql_audit { int interface_version; void (*release_thd)(MYSQL_THD); - void (*event_notify)(MYSQL_THD, const struct mysql_event *); + void (*event_notify)(MYSQL_THD, unsigned int, const void *); unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; }; === modified file 'include/mysql/plugin_audit.h.pp' --- a/include/mysql/plugin_audit.h.pp 2011-03-04 12:12:31 +0000 +++ b/include/mysql/plugin_audit.h.pp 2011-06-02 08:34:10 +0000 @@ -43,7 +43,7 @@ typedef enum _thd_wait_type_e { THD_WAIT_BINLOG= 8, THD_WAIT_GROUP_COMMIT= 9, THD_WAIT_SYNC= 10, - THD_WAIT_LAST= 11 + THD_WAIT_LAST= 11 } thd_wait_type; extern struct thd_wait_service_st { void (*thd_wait_begin_func)(void*, int); @@ -195,13 +195,8 @@ void mysql_query_cache_invalidate4(void* void *thd_get_ha_data(const void* thd, const struct handlerton *hton); void thd_set_ha_data(void* thd, const struct handlerton *hton, const void *ha_data); -struct mysql_event -{ - unsigned int event_class; -}; struct mysql_event_general { - unsigned int event_class; unsigned int event_subclass; int general_error_code; unsigned long general_thread_id; @@ -217,7 +212,6 @@ struct mysql_event_general }; struct mysql_event_connection { - unsigned int event_class; unsigned int event_subclass; int status; unsigned long thread_id; @@ -240,6 +234,6 @@ struct st_mysql_audit { int interface_version; void (*release_thd)(void*); - void (*event_notify)(void*, const struct mysql_event *); + void (*event_notify)(void*, unsigned int, const void *); unsigned long class_mask[1]; }; === modified file 'plugin/audit_null/audit_null.c' --- a/plugin/audit_null/audit_null.c 2010-08-12 15:19:57 +0000 +++ b/plugin/audit_null/audit_null.c 2011-06-02 08:34:10 +0000 @@ -81,11 +81,12 @@ static int audit_null_plugin_deinit(void */ static void audit_null_notify(MYSQL_THD thd __attribute__((unused)), - const struct mysql_event *event) + unsigned int event_class, + const void *event) { /* prone to races, oh well */ number_of_calls++; - if (event->event_class == MYSQL_AUDIT_GENERAL_CLASS) + if (event_class == MYSQL_AUDIT_GENERAL_CLASS) { const struct mysql_event_general *event_general= (const struct mysql_event_general *) event; === modified file 'sql/sql_audit.cc' --- a/sql/sql_audit.cc 2010-12-14 14:34:23 +0000 +++ b/sql/sql_audit.cc 2011-06-02 08:34:10 +0000 @@ -21,11 +21,18 @@ extern int finalize_audit_plugin(st_plug #ifndef EMBEDDED_LIBRARY +struct st_mysql_event_generic +{ + unsigned int event_class; + const void *event; +}; + unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; static mysql_mutex_t LOCK_audit_mask; -static void event_class_dispatch(THD *thd, const struct mysql_event *event); +static void event_class_dispatch(THD *thd, unsigned int event_class, + const void *event); static inline @@ -64,7 +71,6 @@ typedef void (*audit_handler_t)(THD *thd static void general_class_handler(THD *thd, uint event_subtype, va_list ap) { mysql_event_general event; - event.event_class= MYSQL_AUDIT_GENERAL_CLASS; event.event_subclass= event_subtype; event.general_error_code= va_arg(ap, int); event.general_thread_id= thd ? thd->thread_id : 0; @@ -77,14 +83,13 @@ static void general_class_handler(THD *t event.general_query_length= va_arg(ap, unsigned int); event.general_charset= va_arg(ap, struct charset_info_st *); event.general_rows= (unsigned long long) va_arg(ap, ha_rows); - event_class_dispatch(thd, (const mysql_event*) &event); + event_class_dispatch(thd, MYSQL_AUDIT_GENERAL_CLASS, &event); } static void connection_class_handler(THD *thd, uint event_subclass, va_list ap) { mysql_event_connection event; - event.event_class= MYSQL_AUDIT_CONNECTION_CLASS; event.event_subclass= event_subclass; event.status= va_arg(ap, int); event.thread_id= va_arg(ap, unsigned long); @@ -102,7 +107,7 @@ static void connection_class_handler(THD event.ip_length= va_arg(ap, unsigned int); event.database= va_arg(ap, const char *); event.database_length= va_arg(ap, unsigned int); - event_class_dispatch(thd, (const mysql_event *) &event); + event_class_dispatch(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event); } @@ -433,18 +438,19 @@ int finalize_audit_plugin(st_plugin_int static my_bool plugins_dispatch(THD *thd, plugin_ref plugin, void *arg) { - const struct mysql_event *event= (const struct mysql_event *) arg; + const struct st_mysql_event_generic *event_generic= + (const struct st_mysql_event_generic *) arg; unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; st_mysql_audit *data= plugin_data(plugin, struct st_mysql_audit *); - set_audit_mask(event_class_mask, event->event_class); + set_audit_mask(event_class_mask, event_generic->event_class); /* Check to see if the plugin is interested in this event */ if (check_audit_mask(data->class_mask, event_class_mask)) return 0; /* Actually notify the plugin */ - data->event_notify(thd, event); + data->event_notify(thd, event_generic->event_class, event_generic->event); return 0; } @@ -457,15 +463,20 @@ static my_bool plugins_dispatch(THD *thd @param[in] event */ -static void event_class_dispatch(THD *thd, const struct mysql_event *event) +static void event_class_dispatch(THD *thd, unsigned int event_class, + const void *event) { + struct st_mysql_event_generic event_generic; + event_generic.event_class= event_class; + event_generic.event= event; /* Check if we are doing a slow global dispatch. This event occurs when thd == NULL as it is not associated with any particular thread. */ if (unlikely(!thd)) { - plugin_foreach(thd, plugins_dispatch, MYSQL_AUDIT_PLUGIN, (void*) event); + plugin_foreach(thd, plugins_dispatch, MYSQL_AUDIT_PLUGIN, + (void *) &event_generic); } else { @@ -476,7 +487,7 @@ static void event_class_dispatch(THD *th plugins_last= plugins + thd->audit_class_plugins.elements; for (; plugins < plugins_last; plugins++) - plugins_dispatch(thd, *plugins, (void*) event); + plugins_dispatch(thd, *plugins, (void *) &event_generic); } } --===============6285203959391792235== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/sergey.vojtovich@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: sergey.vojtovich@stripped\ # siwvxl5e3dlrnr2u # target_branch: file:///home/svoj/mysql/server/mysql-5.5-audit/ # testament_sha1: ac6724fcded368993ef0ee466816e4844dd8b915 # timestamp: 2011-06-02 12:34:14 +0400 # base_revision_id: jimmy.yang@stripped\ # az0yyt0m8pjioaf0 # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWXYQFsUABRf/gFAQgBJZd/// f+f/oL////pgCv3I25uWfdjbamsC333mPr593t2jey7d3bOet71OOoZFGmij00TZJk2QNT0aENAD TQAADQAkkBBpoTIamU0j1P1Gpmo0D1AAaAAGagamI00pqabKeoANA9T1AAA0aGjQA0MgJERAgJop +Kn+lT8qP1AT9TSfqBGT1DQPUaAPUaBFIhNNTJ6mKPU9TTajyaZTCNpNMgyGQaAAAkiBEyaZGIVP 1NP1KZpmqejSD0nqaADQaANCz7Gb+j0vfsHxrR4M2NbeqFYnB7qH8jMOHficSGaZu24TPcQLBeOH 6YoJayBtQYqpD6apDXnMAMrI4OSswMkkJzoVzlasyZ6qM43yjJFSwtlIwWlGxeLSGe1/KtoSvSFi az4SnbnrQuaTjzmvxBQOoGk2NobSGw/fs9yFjssy4xxyYhJT4Nlu3IGQZaQ5aucO1zUvuvpusbrS Fa1fEIwsh1upRupF7m92YRewVDBArvlpv3O3FarpOknLceE/MyWoqSpdvoBBsuuICxa0T7SXCaWg TyKExz5EQDSwIhnEIsBTBfihEcIY4Z73o8T70Y9JhVwWWT/roE7UQlcH+yCEMmmPgjSGr7/7sjUo GLEpgUhhuwduuwg5i7Nn2s4MqmDEMn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