Skip to content

Return independently owned value arrays from get_values - #9013

Merged
rzo1 merged 1 commit into
masterfrom
worker-launcher-config-value-arrays
Aug 24, 2026
Merged

Return independently owned value arrays from get_values#9013
rzo1 merged 1 commit into
masterfrom
worker-launcher-config-value-arrays

Conversation

@reiabreu

Copy link
Copy Markdown
Contributor

get_values() returned the array from extract_values_delim() directly. Those entries point into the single buffer that strtok_r tokenizes in place, and 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 → abort.
  • A value made up only of delimiters left extract_values_delim returning a non-NULL, non-NULL-terminated array (the terminator was only written when size > 0).

The behaviour is pre-existing and reachable from any get_values caller (e.g. banned.users); it was raised on #9010 for the new worker.launcher.oci.allowed.mount.source.dirs key, and is split out here since it is not OCI-specific.

Changes:

  • get_values 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 (leading, trailing, and delimiter-only values); it aborts on the pre-fix code.

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
rzo1 merged commit 0ffeec2 into master Aug 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants