Skip to content

Bug#120580: Keep ignorable prefix characters in string range candidates - #786

Open
DerZc wants to merge 2 commits into
mysql:trunkfrom
DerZc:fix-bug-120580
Open

DerZc wants to merge 2 commits into
mysql:trunkfrom
DerZc:fix-bug-120580

Conversation

@DerZc

@DerZc DerZc commented Sep 28, 2026 •

Copy link
Copy Markdown

What does this change do?

A partial key containing only primary-ignorable characters can sort below its complete value. For the affected utf8mb4_0900_ai_ci prefix range, retain all non-NULL candidates and recheck the full comparison. Update the MyISAM and InnoDB ICP EXPLAIN expectations for the widened scan bounds; query-result rows remain unchanged.

Bug report: https://bugs.mysql.com/bug.php?id=120580

Why is it needed?

The affected execution path returns a different query result from the equivalent reference. The change preserves the expression or access-path semantics described above.

How was it tested?

On trunk at a1ef44f1d327b940a763b25eee2c6e146a0ebdb0:

  • The unmodified server fails the new regression with a result mismatch.

  • The patched server builds successfully.

  • 40 query-result checks pass against separately established expected results, including repeated prepared statements.

  • Native MTR passes: main.bug_120580, main.select_count, main.range_all, main.range_icp_mrr, main.innodb_icp, main.myisam_icp.

  • The regression passes with the prepared-statement protocol.

  • The full database regression suite was not run.

  • Added MTR coverage under mysql-test/.

  • Ran scripts/ci/mtr.sh with its default selection; the explicit native and related tests above were run instead.

  • Ran the full database regression suite.

Contributor checklist

  • Changed C++ files are formatted with the repository .clang-format.
  • One focused commit with a descriptive message.

AI assistance

  • I did not use AI assistance for this contribution.
  • I used AI assistance for this contribution.

OpenAI Codex assisted with implementation, regression test generation and review. The submitted change was checked with compilation, execution against independently established expected results, a failing unpatched regression, and the MTR tests listed above. No human review is claimed by these automated checks.

Areas touched

mysql-test, sql

Add daily MTR coverage, update the clang-format workflow, and tighten
CI safeguards.

Include the component_mysql_rest_service suite in the daily and PR MTR
matrices so all default suites receive coverage.

Require approved integrity for Codex PR-review content and require the
OCA Verified label for both automatic and requested reviews. Review when
verification is applied, and omit the opened trigger to avoid duplicate
opening and verification runs.

Regenerate the Codex PR review lockfile with gh-aw v0.89.20, retaining
the corrected daily AIC accounting, and mark generated workflow lockfiles
for GitHub Linguist.

Bug#40059173: Add the required copyright notices to the CI shell scripts
and generated workflow lockfile.

Change-Id: Ia803f82b247130de88225e50ef196fa1467cf5aa
@DerZc
DerZc requested a review from a team September 28, 2026 06:25
@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Sep 28, 2026
@github-actions github-actions Bot added Optimizer Changes touching optimizer code Tests Changes touching test code or test data labels Sep 28, 2026
A partial key containing only primary-ignorable characters can sort
below its complete value. For the affected utf8mb4_0900_ai_ci prefix
range, retain all non-NULL candidates and recheck the full comparison.
Update the MyISAM and InnoDB ICP EXPLAIN expectations for the widened
scan bounds; query-result rows remain unchanged.

Add native regressions for the reported query, equivalent controls, and
repeated prepared-statement execution. Preserve observable results
across the affected execution paths.

Bug report: https://bugs.mysql.com/bug.php?id=120580
@github-actions github-actions Bot added the Build Passed PR build passed label Sep 28, 2026
@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement Bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Sep 28, 2026
@github-actions github-actions Bot added the Review Requested Review requested from code owners label Sep 28, 2026
@RidhaOracle

Copy link
Copy Markdown
Member

/codex

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Codex PR Review completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by Codex PR Review for #786

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the five changed files at 1f867a14; no high-confidence actionable defects found. The widened lower bound retains non-NULL candidates and marks the range inexact for full predicate filtering. The regression coverage and updated ICP expectations are consistent with that behavior.

Static review only: PR code and tests were not executed.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by Codex PR Review for #786 · codex · gpt60 · 98.8 AIC · ⌖ 23.7 AIC · ⊞ 14K
Comment /codex to run again

@github-actions github-actions Bot added the MTR Failed MTR suite failed label Sep 28, 2026
inikep pushed a commit to Percona-Lab/percona-server-linear that referenced this pull request Oct 7, 2026
Blueprint
https://blueprints.launchpad.net/percona-server/+spec/audit-log-default-db

Add field `DB' for `MYSQL_AUDIT_GENERAL_STATUS' records.

==========================================

[mysql#786] Bug 1610242: Reading past the end of heap buffer on saving the default DB in audit p

Original title:
[mysql#786] Bug 1610242: Reading past the end of heap buffer on saving the default DB in audit plugin

memcpy in the call

memcpy(local->db, event_general->general_query, sizeof(local->db));

always copies `NAME_LEN' bytes, but the real length of the
`general_query' can be less than `NAME_LEN'

Fix is to copy `general_query_length' bytes.

==========================================

[#930] Bug 1613647: Sporadic audit_log_filter_users failures

Insert silent statements (which aren't are grepped away) before
connects to make sure the previous statement we which want to see in
the audit log actually gets there before the connect.

==========================================

[#941] Bug 1617833: audit_log_default_db failures

1. Insert silent statement after UNINSTALL PLUGIN to make sure that SHOW
   WARNINGS is logged before the statement from the next connection.

2. Insert silent statement before establishing the connection which does
   'INSTALL PLUGIN', make sure 'SELECT * FROM t' gets to the log.

3. Make reconnect in case of error optional for 'change_user' mysqltest
   command

==========================================

[#1682] Bug 1650294: Test main.audit_log_filter_users is unstable

The source of instability is the fact that event of creating new
connection and closing previous one are not synchronized. It makes
"Quit" record to appear after "Connect" one.

Fix is to replace `include/wait_until_disconnected.inc' which waits for
client connection to be closed with
`include/wait_until_count_sessions.inc' which waits for specific
`Threads_connected' value which is updated after
`MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT'.

==========================================

[#1762] Bug 1626559: Test `main.audit_log_default_db' is unstable

Sometimes "SHOW WARNINGS" appears in the audit log around UNINSTALL
PLUGIN / INSTALL PLUGIN. This is the warning which MySQL issue about
plugin being in use.

Normally warning should not make it to audit log because test case
truncates log after UNINSTALL PLUGIN. But sometimes mysql-test picks
this warning up after plugin has been reinstalled and it gets logged
into audit log.

This patch makes sure that test execution continues only when plugin
disappeared from the `mysql.plgins', which happens after `deinit' is
called and all plugin is fully shut down.

==========================================

[mysql#736] Allow to log only queries for specific DBs in audit log plugin

Blueprint:

[https://blueprints.launchpad.net/percona-server/+spec/audit-filer-db]

Add two global variables:

- `audit_log_include_databases' comma separated list of databases to
  include in audit logging
- `audit_log_exclude_databases' comma separated list of databases to
  exclude from audit logging

Allow escaped backticks in the `next_word' function. This change needs
to be backported to the 5.6.

Patch changes behaviour of user and database filters. User filter
becomes case sensitive for user name and case insensitive for host name.
Database filter becomes case insensitive.

[#931] Bug 1617828: audit_log_filter_db failures

The fix increases timeout for event shot wait to 10 minutes and adds
silent query at the end of the event.

============================================================

[mysql#826] Add filtering by `sql_command'

Blueprint:

https://blueprints.launchpad.net/percona-server/+spec/audit-filer-command

- add option `audit_log_include_command' to specify commands to log
- add option `audit_log_exclude_command' to specify commands to exclude
  from logging
- backport changes for `next_word' fixing the capture of default
  database with quoted backticks.
- backport case-sensitivity fix for account filters

==========================================

[#1381] Bug 1650321: Valgrind error on main.audit_log_filter_commands

Valgrind complained about `cmd' being used uninitialized. However, I
don't a path when it could happen, since the first command was to
initialize it unconditionally.

Still this error message pointed me to the fact that we don't need `cmd'
at all, we can simply use `name' and `length' provided as arguments.

==========================================

[#1444] Bug 1663251: ASan errors on main.audit_log_filter_commands

`my_hash_search' takes two arguments - key to search for and it's
length. When length is 0, `my_hash_search' considers that key has the
same length as hash length.

Since this behaviour may be relied on somewhere, the fix is to avoid
calling `my_hash_search' for empty strings.

==========================================

[mysql#846] Bug 1614444: Assertion `local->stack.frames[local->stack.top].query == event_general->general_query.str' failed

It is a bug which can affects filtering by DB for triggers.

There is a trigger

    CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @Aux=1;

and query

    INSERT INTO t1(c5,c6)VALUES (1,0);

Lets see which events are sent to the audit_log:

1. TABLE ACCESS event for "INSERT INTO t1(c5,c6)VALUES (1,0)"
2. STATUS event for "SET @Aux=1"
3. STATUS event for "INSERT INTO t1(c5,c6)VALUES (1,0)"

When (1) comes, plugin pushes "INSERT INTO t1(c5,c6)VALUES (1,0)" to
the top of the stack, so it can match it later with STATUS event.

When (2) comes, plugin is trying to match "SET @Aux=1" against the stack
top. But "SET @Aux=1" isn't on the stack since it doesn't access any
database. In debug mode we see the assertion failure. In the release
mode, "SET @Aux=1" will be attributed as accessing table "t1", which is
wrong.

The fix is to replace assert with if statement. Now the query the within
trigger which doesn't access any database will always be logged just
like any similar query executed outside of the trigger.

============================================================

[#1176] Bug 1641910: Trying to set audit_log_exclude_accounts crashes server

The root cause of this bug is that logic around filtering variables rely
heavily on the fact that CHECK and UPDATE functions are always called.
This is not true when variables passed via defaults file or set as
command line options.

The fix is add special handling for filtering variables on startup.

==========================================

[#1451] Bug 1666496: Server crashes on startup if plugin is unable to create file pointed by --audit_log_file

In order to expose this bug we need to set both
--audit-log-exclude-commands and --audit-log-file at start up.

Second one has to be incorrect, so that plugin would refuse to start
with error:

    mysqld: File './data-dir/mysql-audit.json' not found (Errcode: 2 - No such file or directory)
    2017-02-21T11:58:42.392280Z 0 [ERROR] Plugin audit_log reported: 'Cannot open file ./data-dir/mysql-audit.json.'
    2017-02-21T11:58:42.392350Z 0 [ERROR] Plugin audit_log reported: 'Error: No such file or directory'
    2017-02-21T11:58:42.392355Z 0 [ERROR] Plugin 'audit_log' init function returned error.
    2017-02-21T11:58:42.392360Z 0 [ERROR] Plugin 'audit_log' registration as a AUDIT failed.

The cause for the crash is common with bug 1641910. MEMALLOC'ed
variables are not properly initialized by server (UPDATE and CHECK
functions aren't invoked).

The fix is to make sure that initialization of MEMALLOC'ed variables is
the very first thing we do.

==========================================

[#2032] lp1716844: Escaping control characters in the audit log

Implemented escaping for the JSON output format, and updated the test suite.

The other output formats are left unchanged, as they do not have a well defined method for escaping these characters.
XML does support control characters in version 1.1, but most tools only understand 1.0, and our output is 1.0.

==========================================

[g5]PS-5363 (Merge MySQL 8.0.17): fixed audit_log.audit_log_default_db MTR test case

Similarly to what Oracle did in treir fix for Bug #29248047
"5.7 AUDIT PLUGIN DOES NOT LOG WHO UNINSTALLS THE AUDIT PLUGIN UNLIKE 5.6"
(commit mysql/mysql-server@6a893b8)
added '--source include/disconnect_connections.inc' to
'audit_log.audit_log_default_db' MTR test case after plugin uninstallation.
inikep pushed a commit to Percona-Lab/percona-server-linear that referenced this pull request Oct 7, 2026
Blueprint
https://blueprints.launchpad.net/percona-server/+spec/audit-log-default-db

Add field `DB' for `MYSQL_AUDIT_GENERAL_STATUS' records.

==========================================

[mysql#786] Bug 1610242: Reading past the end of heap buffer on saving the default DB in audit p

Original title:
[mysql#786] Bug 1610242: Reading past the end of heap buffer on saving the default DB in audit plugin

memcpy in the call

memcpy(local->db, event_general->general_query, sizeof(local->db));

always copies `NAME_LEN' bytes, but the real length of the
`general_query' can be less than `NAME_LEN'

Fix is to copy `general_query_length' bytes.

==========================================

[#930] Bug 1613647: Sporadic audit_log_filter_users failures

Insert silent statements (which aren't are grepped away) before
connects to make sure the previous statement we which want to see in
the audit log actually gets there before the connect.

==========================================

[#941] Bug 1617833: audit_log_default_db failures

1. Insert silent statement after UNINSTALL PLUGIN to make sure that SHOW
   WARNINGS is logged before the statement from the next connection.

2. Insert silent statement before establishing the connection which does
   'INSTALL PLUGIN', make sure 'SELECT * FROM t' gets to the log.

3. Make reconnect in case of error optional for 'change_user' mysqltest
   command

==========================================

[#1682] Bug 1650294: Test main.audit_log_filter_users is unstable

The source of instability is the fact that event of creating new
connection and closing previous one are not synchronized. It makes
"Quit" record to appear after "Connect" one.

Fix is to replace `include/wait_until_disconnected.inc' which waits for
client connection to be closed with
`include/wait_until_count_sessions.inc' which waits for specific
`Threads_connected' value which is updated after
`MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT'.

==========================================

[#1762] Bug 1626559: Test `main.audit_log_default_db' is unstable

Sometimes "SHOW WARNINGS" appears in the audit log around UNINSTALL
PLUGIN / INSTALL PLUGIN. This is the warning which MySQL issue about
plugin being in use.

Normally warning should not make it to audit log because test case
truncates log after UNINSTALL PLUGIN. But sometimes mysql-test picks
this warning up after plugin has been reinstalled and it gets logged
into audit log.

This patch makes sure that test execution continues only when plugin
disappeared from the `mysql.plgins', which happens after `deinit' is
called and all plugin is fully shut down.

==========================================

[mysql#736] Allow to log only queries for specific DBs in audit log plugin

Blueprint:

[https://blueprints.launchpad.net/percona-server/+spec/audit-filer-db]

Add two global variables:

- `audit_log_include_databases' comma separated list of databases to
  include in audit logging
- `audit_log_exclude_databases' comma separated list of databases to
  exclude from audit logging

Allow escaped backticks in the `next_word' function. This change needs
to be backported to the 5.6.

Patch changes behaviour of user and database filters. User filter
becomes case sensitive for user name and case insensitive for host name.
Database filter becomes case insensitive.

[#931] Bug 1617828: audit_log_filter_db failures

The fix increases timeout for event shot wait to 10 minutes and adds
silent query at the end of the event.

============================================================

[mysql#826] Add filtering by `sql_command'

Blueprint:

https://blueprints.launchpad.net/percona-server/+spec/audit-filer-command

- add option `audit_log_include_command' to specify commands to log
- add option `audit_log_exclude_command' to specify commands to exclude
  from logging
- backport changes for `next_word' fixing the capture of default
  database with quoted backticks.
- backport case-sensitivity fix for account filters

==========================================

[#1381] Bug 1650321: Valgrind error on main.audit_log_filter_commands

Valgrind complained about `cmd' being used uninitialized. However, I
don't a path when it could happen, since the first command was to
initialize it unconditionally.

Still this error message pointed me to the fact that we don't need `cmd'
at all, we can simply use `name' and `length' provided as arguments.

==========================================

[#1444] Bug 1663251: ASan errors on main.audit_log_filter_commands

`my_hash_search' takes two arguments - key to search for and it's
length. When length is 0, `my_hash_search' considers that key has the
same length as hash length.

Since this behaviour may be relied on somewhere, the fix is to avoid
calling `my_hash_search' for empty strings.

==========================================

[mysql#846] Bug 1614444: Assertion `local->stack.frames[local->stack.top].query == event_general->general_query.str' failed

It is a bug which can affects filtering by DB for triggers.

There is a trigger

    CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @Aux=1;

and query

    INSERT INTO t1(c5,c6)VALUES (1,0);

Lets see which events are sent to the audit_log:

1. TABLE ACCESS event for "INSERT INTO t1(c5,c6)VALUES (1,0)"
2. STATUS event for "SET @Aux=1"
3. STATUS event for "INSERT INTO t1(c5,c6)VALUES (1,0)"

When (1) comes, plugin pushes "INSERT INTO t1(c5,c6)VALUES (1,0)" to
the top of the stack, so it can match it later with STATUS event.

When (2) comes, plugin is trying to match "SET @Aux=1" against the stack
top. But "SET @Aux=1" isn't on the stack since it doesn't access any
database. In debug mode we see the assertion failure. In the release
mode, "SET @Aux=1" will be attributed as accessing table "t1", which is
wrong.

The fix is to replace assert with if statement. Now the query the within
trigger which doesn't access any database will always be logged just
like any similar query executed outside of the trigger.

============================================================

[#1176] Bug 1641910: Trying to set audit_log_exclude_accounts crashes server

The root cause of this bug is that logic around filtering variables rely
heavily on the fact that CHECK and UPDATE functions are always called.
This is not true when variables passed via defaults file or set as
command line options.

The fix is add special handling for filtering variables on startup.

==========================================

[#1451] Bug 1666496: Server crashes on startup if plugin is unable to create file pointed by --audit_log_file

In order to expose this bug we need to set both
--audit-log-exclude-commands and --audit-log-file at start up.

Second one has to be incorrect, so that plugin would refuse to start
with error:

    mysqld: File './data-dir/mysql-audit.json' not found (Errcode: 2 - No such file or directory)
    2017-02-21T11:58:42.392280Z 0 [ERROR] Plugin audit_log reported: 'Cannot open file ./data-dir/mysql-audit.json.'
    2017-02-21T11:58:42.392350Z 0 [ERROR] Plugin audit_log reported: 'Error: No such file or directory'
    2017-02-21T11:58:42.392355Z 0 [ERROR] Plugin 'audit_log' init function returned error.
    2017-02-21T11:58:42.392360Z 0 [ERROR] Plugin 'audit_log' registration as a AUDIT failed.

The cause for the crash is common with bug 1641910. MEMALLOC'ed
variables are not properly initialized by server (UPDATE and CHECK
functions aren't invoked).

The fix is to make sure that initialization of MEMALLOC'ed variables is
the very first thing we do.

==========================================

[#2032] lp1716844: Escaping control characters in the audit log

Implemented escaping for the JSON output format, and updated the test suite.

The other output formats are left unchanged, as they do not have a well defined method for escaping these characters.
XML does support control characters in version 1.1, but most tools only understand 1.0, and our output is 1.0.

==========================================

[g5]PS-5363 (Merge MySQL 8.0.17): fixed audit_log.audit_log_default_db MTR test case

Similarly to what Oracle did in treir fix for Bug #29248047
"5.7 AUDIT PLUGIN DOES NOT LOG WHO UNINSTALLS THE AUDIT PLUGIN UNLIKE 5.6"
(commit mysql/mysql-server@6a893b8)
added '--source include/disconnect_connections.inc' to
'audit_log.audit_log_default_db' MTR test case after plugin uninstallation.
@github-actions

Copy link
Copy Markdown

Marking as stale due to inactivity. Push or comment to keep it open.

@github-actions github-actions Bot added the Stale label Oct 19, 2026
@github-actions github-actions Bot removed the Stale label Oct 21, 2026
jankowsk pushed a commit to Percona-Lab/percona-server-linear that referenced this pull request Oct 26, 2026
Blueprint
https://blueprints.launchpad.net/percona-server/+spec/audit-log-default-db

Add field `DB' for `MYSQL_AUDIT_GENERAL_STATUS' records.

==========================================

[mysql#786] Bug 1610242: Reading past the end of heap buffer on saving the default DB in audit p

Original title:
[mysql#786] Bug 1610242: Reading past the end of heap buffer on saving the default DB in audit plugin

memcpy in the call

memcpy(local->db, event_general->general_query, sizeof(local->db));

always copies `NAME_LEN' bytes, but the real length of the
`general_query' can be less than `NAME_LEN'

Fix is to copy `general_query_length' bytes.

==========================================

[#930] Bug 1613647: Sporadic audit_log_filter_users failures

Insert silent statements (which aren't are grepped away) before
connects to make sure the previous statement we which want to see in
the audit log actually gets there before the connect.

==========================================

[#941] Bug 1617833: audit_log_default_db failures

1. Insert silent statement after UNINSTALL PLUGIN to make sure that SHOW
   WARNINGS is logged before the statement from the next connection.

2. Insert silent statement before establishing the connection which does
   'INSTALL PLUGIN', make sure 'SELECT * FROM t' gets to the log.

3. Make reconnect in case of error optional for 'change_user' mysqltest
   command

==========================================

[#1682] Bug 1650294: Test main.audit_log_filter_users is unstable

The source of instability is the fact that event of creating new
connection and closing previous one are not synchronized. It makes
"Quit" record to appear after "Connect" one.

Fix is to replace `include/wait_until_disconnected.inc' which waits for
client connection to be closed with
`include/wait_until_count_sessions.inc' which waits for specific
`Threads_connected' value which is updated after
`MYSQL_AUDIT_NOTIFY_CONNECTION_DISCONNECT'.

==========================================

[#1762] Bug 1626559: Test `main.audit_log_default_db' is unstable

Sometimes "SHOW WARNINGS" appears in the audit log around UNINSTALL
PLUGIN / INSTALL PLUGIN. This is the warning which MySQL issue about
plugin being in use.

Normally warning should not make it to audit log because test case
truncates log after UNINSTALL PLUGIN. But sometimes mysql-test picks
this warning up after plugin has been reinstalled and it gets logged
into audit log.

This patch makes sure that test execution continues only when plugin
disappeared from the `mysql.plgins', which happens after `deinit' is
called and all plugin is fully shut down.

==========================================

[mysql#736] Allow to log only queries for specific DBs in audit log plugin

Blueprint:

[https://blueprints.launchpad.net/percona-server/+spec/audit-filer-db]

Add two global variables:

- `audit_log_include_databases' comma separated list of databases to
  include in audit logging
- `audit_log_exclude_databases' comma separated list of databases to
  exclude from audit logging

Allow escaped backticks in the `next_word' function. This change needs
to be backported to the 5.6.

Patch changes behaviour of user and database filters. User filter
becomes case sensitive for user name and case insensitive for host name.
Database filter becomes case insensitive.

[#931] Bug 1617828: audit_log_filter_db failures

The fix increases timeout for event shot wait to 10 minutes and adds
silent query at the end of the event.

============================================================

[mysql#826] Add filtering by `sql_command'

Blueprint:

https://blueprints.launchpad.net/percona-server/+spec/audit-filer-command

- add option `audit_log_include_command' to specify commands to log
- add option `audit_log_exclude_command' to specify commands to exclude
  from logging
- backport changes for `next_word' fixing the capture of default
  database with quoted backticks.
- backport case-sensitivity fix for account filters

==========================================

[#1381] Bug 1650321: Valgrind error on main.audit_log_filter_commands

Valgrind complained about `cmd' being used uninitialized. However, I
don't a path when it could happen, since the first command was to
initialize it unconditionally.

Still this error message pointed me to the fact that we don't need `cmd'
at all, we can simply use `name' and `length' provided as arguments.

==========================================

[#1444] Bug 1663251: ASan errors on main.audit_log_filter_commands

`my_hash_search' takes two arguments - key to search for and it's
length. When length is 0, `my_hash_search' considers that key has the
same length as hash length.

Since this behaviour may be relied on somewhere, the fix is to avoid
calling `my_hash_search' for empty strings.

==========================================

[mysql#846] Bug 1614444: Assertion `local->stack.frames[local->stack.top].query == event_general->general_query.str' failed

It is a bug which can affects filtering by DB for triggers.

There is a trigger

    CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @Aux=1;

and query

    INSERT INTO t1(c5,c6)VALUES (1,0);

Lets see which events are sent to the audit_log:

1. TABLE ACCESS event for "INSERT INTO t1(c5,c6)VALUES (1,0)"
2. STATUS event for "SET @Aux=1"
3. STATUS event for "INSERT INTO t1(c5,c6)VALUES (1,0)"

When (1) comes, plugin pushes "INSERT INTO t1(c5,c6)VALUES (1,0)" to
the top of the stack, so it can match it later with STATUS event.

When (2) comes, plugin is trying to match "SET @Aux=1" against the stack
top. But "SET @Aux=1" isn't on the stack since it doesn't access any
database. In debug mode we see the assertion failure. In the release
mode, "SET @Aux=1" will be attributed as accessing table "t1", which is
wrong.

The fix is to replace assert with if statement. Now the query the within
trigger which doesn't access any database will always be logged just
like any similar query executed outside of the trigger.

============================================================

[#1176] Bug 1641910: Trying to set audit_log_exclude_accounts crashes server

The root cause of this bug is that logic around filtering variables rely
heavily on the fact that CHECK and UPDATE functions are always called.
This is not true when variables passed via defaults file or set as
command line options.

The fix is add special handling for filtering variables on startup.

==========================================

[#1451] Bug 1666496: Server crashes on startup if plugin is unable to create file pointed by --audit_log_file

In order to expose this bug we need to set both
--audit-log-exclude-commands and --audit-log-file at start up.

Second one has to be incorrect, so that plugin would refuse to start
with error:

    mysqld: File './data-dir/mysql-audit.json' not found (Errcode: 2 - No such file or directory)
    2017-02-21T11:58:42.392280Z 0 [ERROR] Plugin audit_log reported: 'Cannot open file ./data-dir/mysql-audit.json.'
    2017-02-21T11:58:42.392350Z 0 [ERROR] Plugin audit_log reported: 'Error: No such file or directory'
    2017-02-21T11:58:42.392355Z 0 [ERROR] Plugin 'audit_log' init function returned error.
    2017-02-21T11:58:42.392360Z 0 [ERROR] Plugin 'audit_log' registration as a AUDIT failed.

The cause for the crash is common with bug 1641910. MEMALLOC'ed
variables are not properly initialized by server (UPDATE and CHECK
functions aren't invoked).

The fix is to make sure that initialization of MEMALLOC'ed variables is
the very first thing we do.

==========================================

[#2032] lp1716844: Escaping control characters in the audit log

Implemented escaping for the JSON output format, and updated the test suite.

The other output formats are left unchanged, as they do not have a well defined method for escaping these characters.
XML does support control characters in version 1.1, but most tools only understand 1.0, and our output is 1.0.

==========================================

[g5]PS-5363 (Merge MySQL 8.0.17): fixed audit_log.audit_log_default_db MTR test case

Similarly to what Oracle did in treir fix for Bug #29248047
"5.7 AUDIT PLUGIN DOES NOT LOG WHO UNINSTALLS THE AUDIT PLUGIN UNLIKE 5.6"
(commit mysql/mysql-server@6a893b8)
added '--source include/disconnect_connections.inc' to
'audit_log.audit_log_default_db' MTR test case after plugin uninstallation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Passed PR build passed MTR Failed MTR suite failed OCA Verified All contributors have signed the Oracle Contributor Agreement. Optimizer Changes touching optimizer code Review Requested Review requested from code owners Tests Changes touching test code or test data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants