Repository navigation
fix stack buffer overflow in SaveAsFile backup path construction - #6420
Open
Dhanu-dynamic wants to merge 1 commit into
Open
Dhanu-dynamic wants to merge 1 commit into
Dhanu-dynamic wants to merge 1 commit into
Conversation
larsewi
requested changes
Oct 19, 2026
larsewi
left a comment
Contributor
There was a problem hiding this comment.
Please remove the test. The fix is easy enough to verify by reading it. And the test tests a side effect, not the behavior. Otherwise LGTM, thanks 🚀
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
Dhanu-dynamic
force-pushed
the
saveasfile-backup-path-overflow
branch
from
October 20, 2026 08:21
714cda2 to
e1d058e
Compare
Contributor
Author
|
Dropped the unit test and the |
Contributor
|
@cf-bottom Jenkins please :) |
|
Alright, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/14827/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14827/ |
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.
Repro: run an
edit_line(oredit_xml) files promise whose promiser is a symlink pointing to a target path nearCF_BUFSIZElong;cf-agentcrashes (ASan: stack-buffer-overflow inSaveAsFile).Cause: after
SaveAsFile()dereferences the symlink chain intoderef_file(aBuffer, so up toCF_BUFSIZE), it builds the.cf-before-editbackup name and.cf-after-edittemp name withstrcpy()/strcat()into the fixedbackup[CF_BUFSIZE]andnew[CF_BUFSIZE]stack buffers, plus a timestamp. A dereferenced path close toCF_BUFSIZEoverruns both buffers. Reached from any files promise withedit_line/edit_xmlviaFinishEditContext->SaveItemListAsFile->SaveAsFile.Fix: use
strlcpy/strlcatand refuse the edit (as the function already does on other failures) when the backup/temp name would not fit, matching the bounded copies already used a few lines above in this file.Verified with AddressSanitizer: a unit test in
tests/unit/files_operators_test.c(drivingSaveItemListAsFileover a long symlink target) and a realcf-agentedit_line run both trip the overflow before the change and are clean after. Full unit suite stays green under-fsanitize=address.