Return independently owned value arrays from get_values - #9013
Merged
Conversation
get_values returned the array from extract_values_delim directly, whose entries point into the single buffer that strtok_r tokenized in place. free_values then freed values[0] as if it were that buffer, which only holds when the first token starts at the buffer: a value with a leading delimiter (e.g. ",a") left free_values calling free() on an interior pointer, and a value made up only of delimiters produced an array that was never NULL-terminated. get_values now copies the tokens into an independently owned, NULL-terminated array and frees the parsed buffer itself; free_values frees each element and the array (and no longer dereferences a NULL argument before checking it); extract_values_delim NULL-terminates the zero-token case. Adds test_get_values_degenerate covering leading, trailing, and delimiter-only values. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rzo1
approved these changes
Aug 24, 2026
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.
get_values()returned the array fromextract_values_delim()directly. Those entries point into the single buffer thatstrtok_rtokenizes in place, andfree_values()then freedvalues[0]as if it were that buffer — which only holds when the first token starts at the buffer.,a) leftfree_valuescallingfree()on an interior pointer → abort.extract_values_delimreturning a non-NULL, non-NULL-terminated array (the terminator was only written whensize > 0).The behaviour is pre-existing and reachable from any
get_valuescaller (e.g.banned.users); it was raised on #9010 for the newworker.launcher.oci.allowed.mount.source.dirskey, and is split out here since it is not OCI-specific.Changes:
get_valuescopies the tokens into an independently owned, NULL-terminated array and frees the parsed buffer itself.free_valuesfrees each element and the array, and no longer dereferences a NULL argument before checking it.extract_values_delimNULL-terminates the zero-token case.test_get_values_degenerate(leading, trailing, and delimiter-only values); it aborts on the pre-fix code.