Skip to content

Commit

Permalink
Merge pull request #5427 from oleksandr-kachan/PS-9369-8.0
Browse files Browse the repository at this point in the history
PS-9369: Fix currently processed query comparison in audit_log
  • Loading branch information
oleksandr-kachan authored Oct 1, 2024
2 parents db73f66 + e2e7d52 commit 420bf0b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions plugin/audit_log/audit_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ struct query_stack_frame {
/* number of accessed databases */
int databases_accessed;
/* query */
const char *query;
MYSQL_LEX_CSTRING query;
};

struct query_stack {
Expand Down Expand Up @@ -977,8 +977,12 @@ static bool audit_log_update_thd_local(MYSQL_THD thd,
if (event_general->event_subclass == MYSQL_AUDIT_GENERAL_STATUS) {
local->skip_query = false;

if (local->stack.frames[local->stack.top].query ==
event_general->general_query.str) {
if (event_general->general_query.length != 0 &&
local->stack.frames[local->stack.top].query.length ==
event_general->general_query.length &&
strncmp(local->stack.frames[local->stack.top].query.str,
event_general->general_query.str,
event_general->general_query.length) == 0) {
local->skip_query |=
audit_log_include_databases &&
local->stack.frames[local->stack.top].databases_accessed > 0 &&
Expand All @@ -993,7 +997,8 @@ static bool audit_log_update_thd_local(MYSQL_THD thd,
local->stack.frames[local->stack.top].databases_included = 0;
local->stack.frames[local->stack.top].databases_accessed = 0;
local->stack.frames[local->stack.top].databases_excluded = 0;
local->stack.frames[local->stack.top].query = nullptr;
local->stack.frames[local->stack.top].query.str = nullptr;
local->stack.frames[local->stack.top].query.length = 0;

if (local->stack.top > 0) --local->stack.top;
}
Expand Down Expand Up @@ -1060,12 +1065,15 @@ static bool audit_log_update_thd_local(MYSQL_THD thd,
const mysql_event_table_access *event_table =
(const mysql_event_table_access *)event;

if (local->stack.frames[local->stack.top].query != event_table->query.str &&
local->stack.frames[local->stack.top].query != nullptr) {
if (event_table->query.length != 0 &&
(local->stack.frames[local->stack.top].query.length !=
event_table->query.length ||
strncmp(local->stack.frames[local->stack.top].query.str,
event_table->query.str, event_table->query.length) != 0)) {
if (++local->stack.top >= local->stack.size)
realloc_stack_frames(thd, local->stack.size * 2);
}
local->stack.frames[local->stack.top].query = event_table->query.str;
local->stack.frames[local->stack.top].query = event_table->query;

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

Expand Down

0 comments on commit 420bf0b

Please sign in to comment.