Skip to content

Commit 420bf0b

Browse files
Merge pull request #5427 from oleksandr-kachan/PS-9369-8.0
PS-9369: Fix currently processed query comparison in audit_log
2 parents db73f66 + e2e7d52 commit 420bf0b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

plugin/audit_log/audit_log.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ struct query_stack_frame {
746746
/* number of accessed databases */
747747
int databases_accessed;
748748
/* query */
749-
const char *query;
749+
MYSQL_LEX_CSTRING query;
750750
};
751751

752752
struct query_stack {
@@ -977,8 +977,12 @@ static bool audit_log_update_thd_local(MYSQL_THD thd,
977977
if (event_general->event_subclass == MYSQL_AUDIT_GENERAL_STATUS) {
978978
local->skip_query = false;
979979

980-
if (local->stack.frames[local->stack.top].query ==
981-
event_general->general_query.str) {
980+
if (event_general->general_query.length != 0 &&
981+
local->stack.frames[local->stack.top].query.length ==
982+
event_general->general_query.length &&
983+
strncmp(local->stack.frames[local->stack.top].query.str,
984+
event_general->general_query.str,
985+
event_general->general_query.length) == 0) {
982986
local->skip_query |=
983987
audit_log_include_databases &&
984988
local->stack.frames[local->stack.top].databases_accessed > 0 &&
@@ -993,7 +997,8 @@ static bool audit_log_update_thd_local(MYSQL_THD thd,
993997
local->stack.frames[local->stack.top].databases_included = 0;
994998
local->stack.frames[local->stack.top].databases_accessed = 0;
995999
local->stack.frames[local->stack.top].databases_excluded = 0;
996-
local->stack.frames[local->stack.top].query = nullptr;
1000+
local->stack.frames[local->stack.top].query.str = nullptr;
1001+
local->stack.frames[local->stack.top].query.length = 0;
9971002

9981003
if (local->stack.top > 0) --local->stack.top;
9991004
}
@@ -1060,12 +1065,15 @@ static bool audit_log_update_thd_local(MYSQL_THD thd,
10601065
const mysql_event_table_access *event_table =
10611066
(const mysql_event_table_access *)event;
10621067

1063-
if (local->stack.frames[local->stack.top].query != event_table->query.str &&
1064-
local->stack.frames[local->stack.top].query != nullptr) {
1068+
if (event_table->query.length != 0 &&
1069+
(local->stack.frames[local->stack.top].query.length !=
1070+
event_table->query.length ||
1071+
strncmp(local->stack.frames[local->stack.top].query.str,
1072+
event_table->query.str, event_table->query.length) != 0)) {
10651073
if (++local->stack.top >= local->stack.size)
10661074
realloc_stack_frames(thd, local->stack.size * 2);
10671075
}
1068-
local->stack.frames[local->stack.top].query = event_table->query.str;
1076+
local->stack.frames[local->stack.top].query = event_table->query;
10691077

10701078
++local->stack.frames[local->stack.top].databases_accessed;
10711079

0 commit comments

Comments
 (0)