MDEV-39720: Optimizer Trace doesn't quote string values, may have inv…#5133
Open
spetrunia wants to merge 1 commit into
Open
MDEV-39720: Optimizer Trace doesn't quote string values, may have inv…#5133spetrunia wants to merge 1 commit into
spetrunia wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses MDEV-39720 by ensuring that strings in the Optimizer Trace are properly escaped to prevent invalid JSON output. It refactors string escaping by moving json_escape_to_string to my_json_writer.cc and integrating it directly into Json_writer::add_str. The review feedback highlights two important issues: a potential use-after-free/dangling pointer vulnerability in json_escape_to_string if the input string points to the output buffer during reallocation, and a potential encoding issue caused by hardcoding &my_charset_utf8mb4_bin which may fail for non-UTF-8 input strings.
96232b3 to
2148b23
Compare
12c98be to
a06be02
Compare
19d9377 to
1d75fff
Compare
…alid JSON - Make Json_writer::add_str() do the quoting with json_escape_to_string(). = All other string writing methods are handled as they call this one. - Move json_escape_to_string() from opt_histogram_json.cc to my_json_writer.cc. This is needed because JSON writer unit tests do not link with opt_histogram_json. - Histogram code does its own escaping (with handling for special cases). Add Json_writer::add_escaped_str() to accept escaped strings. This is not intended to be commonly used. - opt_trace_print_expanded_query() did its own escaping for "expanded_query" string. It was done in MDEV-30354. Remove escaping there to avoid double escaping. - dump_record_to_trace() also did own escaping when writing table DDLs into the optimizer trace. Remove double escaping. - Adjust my_json_writer unit test.
1d75fff to
243e7cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…alid JSON