server_audit: Fix double comma in user lists causing incorrect filtering #4598
+1,142
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When SERVER_AUDIT_INCL_USERS or SERVER_AUDIT_EXCL_USERS contains double commas (e.g., 'user1,,user2'), the audit plugin behaves incorrectly:
The root cause is in user_coll_fill(). When parsing a user list string with consecutive commas, the parser calls getkey_user() with the pointer positioned at a comma, which returns cmp_length of 0. Then coll_insert() inserts an empty string into the user collection, corrupting the collection's search behavior.
The fix adds a check to skip empty tokens (when the current character is a comma after whitespace has been skipped) before attempting to extract a username.
Testing
Added 6 MTR tests to verify the fix handles all edge cases:
plugins.server_audit_double_commaincl_users('user1,,user2')plugins.server_audit_excl_double_commaexcl_usersplugins.server_audit_edge_commas',user1,user2,')plugins.server_audit_empty_inputplugins.server_audit_multiple_commas'user1,,,,,user2')plugins.server_audit_whitespace' user1 , user2 ')Test Results - With Fix (MariaDB main branch)
Test Results - Without Fix (Bug Reproduction)
To verify the tests correctly detect the bug, we reverted the fix and ran the tests:
Note:
server_audit_empty_inputpasses without the fix because it tests different behavior - whenincl_userscontains only commas/whitespace (no valid usernames), the expected behavior is to log ALL users (empty inclusion list = no filtering). This is correct behavior that works with or without the fix. The other 5 tests verify the bug scenario where valid usernames are mixed with empty tokens.All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.