Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-9369: Fix currently processed query comparison in audit_log #5427

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading