Fix undefined behavior when using CLI's process command. #307
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.
Issue #, if available: None
Description of changes:
When using the
process
subcommand of the Ion-C CLI theion_cli_command_process
function is called usingNULL
foroutput
ION_STRING parameter. At the end ofion_cli_command_process
as part of the function's cleanup it callsion_cli_close_writer
supplying the NULLoutput
string, which then gets used in a call toion_event_writer_close
, supplying the value and length fields of the ION_STRING to capture the writer's output.Since the output string is NULL, the dereferences to obtain the value and length fields are undefined behavior. ub-san identifies the issue when running a debug build like so:
This PR simply adjusts the call site to supply a NULL for each, if output is NULL. Since we're writing directly to stdout, the output type is IO_TYPE_CONSOLE, ensuring that nothing will be done with the output value pointer and length.
After the PR:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.