Repository navigation
Conversation
Signed-off-by: Aizal Khan <aizumusheer2@gmail.com> (cherry picked from commit 17d6795) Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
cf-agent reconstructs the absolute target of a relative symbolic link by appending the readlink() result onto the link's directory name in a CF_BUFSIZE stack buffer. KillGhostLink() in files_links.c did this with an unbounded strcat(linkpath, linkbuf), and LinkCopy() in verify_files_utils.c with strncat(vbuff, linkbuf, CF_BUFSIZE - 1), whose third argument is the maximum number of bytes to take from the source, not the space left in the destination. readlink() returns up to CF_BUFSIZE - 1 bytes, so a symlink whose relative target is near CF_BUFSIZE, left by an unprivileged user in a directory that a root files promise walks (depth_search, perms, link copy), overflows the stack of the agent. KillGhostLink() runs on every symlink met during a recursive descent, before the dead-link stat(). Bound both appends with strlcat(..., sizeof(buf)), the same way ExpandLinks() in files_links.c already does. KillGhostLink() bails out with an "Internal limit reached" message and LinkCopy() fails the promise when the target does not fit, rather than truncating it into a link pointing somewhere else. Normal links are unchanged. The regression test is skipped when symlink() rejects the long target with ENAMETOOLONG, as macOS does. Changelog: Title Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com> (cherry picked from commit dac3db2) Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
This was referenced Nov 6, 2026
|
Thank you for submitting a pull request! Maybe @craigcomstock can review this? |
Contributor
Author
|
@cf-bottom Jenkins please :) |
|
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/15025/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-15025/ |
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.
Backport of #6209 and #6425.
#6209 is included because #6425 extends the unit test it adds.
🤖 Generated with Claude Code