Skip to content

Made format() reject specifiers that read unpassed printf arguments (3.27.x) - #6477

Open
larsewi wants to merge 1 commit into
cfengine:3.27.xfrom
larsewi:format-reject-unpassed-args-3.27.x
Open

larsewi wants to merge 1 commit into
cfengine:3.27.xfrom
larsewi:format-reject-unpassed-args-3.27.x

Conversation

@larsewi

@larsewi larsewi commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Backport of #6419.

🤖 Generated with Claude Code

FnCallFormat() hands each format piece straight to snprintf() or
BufferAppendF() with exactly one argument. The modifier denylist
("hLqjzt") lets through '*', which takes a width or precision from the
argument list, and '$', which selects a positional argument, so
format("%*d", 7) prints whatever is in the next vararg slot and
format("%2$s", "a") or format("%*s", "a") dereference a slot that was
never passed as a char *. 'l' on %s/%S makes printf read the char *
argument as a wchar_t *, 4 bytes per character past the end of the
string.

The format argument is expanded before the function runs, so a
variable interpolated into it (file contents, module output, data
container values) can carry such a specifier.

Changelog: Title
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
(cherry picked from commit 53ae7d3)
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
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