Skip to content

Made GetExecOutput() return an empty string on empty command output#6226

Merged
aleksandrychev merged 1 commit into
cfengine:masterfrom
aleksandrychev:windows_fix_containers
Jul 9, 2026
Merged

Made GetExecOutput() return an empty string on empty command output#6226
aleksandrychev merged 1 commit into
cfengine:masterfrom
aleksandrychev:windows_fix_containers

Conversation

@aleksandrychev

Copy link
Copy Markdown
Contributor

The read loop never touched the output buffer when the command produced no output: it hit EOF on the first iteration and returned success, leaving the buffer exactly as the caller allocated it. A caller using malloc() then saw stale heap data as command output — this made cf-agent's container inventory intermittently treat a freed 'docker image inspect' JSON buffer as the 'docker volume ls --quiet' result on Windows.

NUL-terminate the buffer up front so callers always get a valid, possibly empty, string.

The read loop never touched the output buffer when the command
produced no output: it hit EOF on the first iteration and returned
success, leaving the buffer exactly as the caller allocated it. A
caller using malloc() then saw stale heap data as command output —
this made cf-agent's container inventory intermittently treat a freed
'docker image inspect' JSON buffer as the 'docker volume ls --quiet'
result on Windows.

NUL-terminate the buffer up front so callers always get a valid,
possibly empty, string.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
@aleksandrychev aleksandrychev merged commit 7924065 into cfengine:master Jul 9, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants