Skip to content

fix stack overflow in ExpandLinks path component parsing#6209

Merged
larsewi merged 1 commit into
cfengine:masterfrom
aizu-m:expandlinks-component-overflow
Jul 17, 2026
Merged

fix stack overflow in ExpandLinks path component parsing#6209
larsewi merged 1 commit into
cfengine:masterfrom
aizu-m:expandlinks-component-overflow

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Found this reading the symlink resolver.

  1. ExpandLinks() splits the path one component at a time with sscanf(sp, "%[^/]", node) into node[CF_MAXLINKSIZE] (256), no field width.

  2. the parse runs before the lstat(), and the recursive call hands readlink() targets (up to CF_BUFSIZE-1) back in as from, so a symlink target that is a single long slash-free component overruns the stack.

     ERROR: AddressSanitizer: stack-buffer-overflow
         WRITE of size 1023
         #1 sscanf
         #2 ExpandLinks files_links.c:710
    

Measured the component with strcspn() first and bail the same way the rest of the function already does on an over-long path. Regression test added under tests/unit.

@cf-bottom

Copy link
Copy Markdown

Thanks for submitting a pull request! Maybe @larsewi can review this?

Comment thread tests/unit/files_links_test.c Outdated
Comment thread libpromises/files_links.c Fixed
@larsewi
larsewi force-pushed the expandlinks-component-overflow branch from d0dc1a3 to 59ef2d1 Compare July 13, 2026 13:29
@larsewi

larsewi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@cf-bottom

Copy link
Copy Markdown

@larsewi

larsewi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Please squash the two commits and rebase :)

Signed-off-by: Aizal Khan <aizumusheer2@gmail.com>
@aizu-m
aizu-m force-pushed the expandlinks-component-overflow branch from 59ef2d1 to 17d6795 Compare July 15, 2026 10:18
@aizu-m

aizu-m commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Done, squashed into one commit and rebased onto latest master.

@larsewi

larsewi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@cf-bottom

Copy link
Copy Markdown

@larsewi
larsewi merged commit ace3200 into cfengine:master Jul 17, 2026
47 of 48 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.

4 participants