From ba03c7076e30bae60d1b3390743d693df83f57ae Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Mon, 16 May 2016 16:29:48 -0700 Subject: [PATCH] Fix segfault in audit plugin codepath Summary: The THD pointer is not always available when the audit plugin is called. The causes a problem when we try to access thd->query_id. Fix by doing a null check first. If the THD is null, then we copy what is done for thread_id, we just set query_id to 0. Squash with: 1def6b7 Expose more information to audit plugin Test Plan: mtr Reviewers: jkedgar, hermanlee4, drilibo Reviewed By: drilibo Subscribers: webscalesql-eng Differential Revision: https://reviews.facebook.net/D58287 --- sql/sql_audit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 5b22476df4db..a6a2b7763e7f 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -92,7 +92,7 @@ static void general_class_handler(THD *thd, uint event_subtype, va_list ap) event.database_length= va_arg(ap, unsigned int); event.query_attributes= va_arg(ap, const char*); event.query_attributes_length= va_arg(ap, unsigned int); - event.query_id= (unsigned long long) thd->query_id; + event.query_id= thd ? (unsigned long long) thd->query_id : 0LL; event_class_dispatch(thd, MYSQL_AUDIT_GENERAL_CLASS, &event); }