Skip to content

Terminate substituted tokens within the caller buffer - #114

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/ppdc-get-token-variable-bound-copy-pr
Nov 19, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/ppdc-get-token-variable-bound-copy-pr

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

get_token substitutes a variable value with strncpy, which may leave the destination unterminated when the value fills the available space. The following strlen and terminator write can then run beyond the caller buffer. Use snprintf so the substitution is bounded and terminated.

get_token() substitutes a #define'd variable's value into the current
token with strncpy(), but strncpy() does not add a terminating NUL
when the source is at least as long as the number of bytes copied.
Once that happens the following strlen() walks off the end of the
caller's buffer (some of which, like get_po()'s 32-byte locale name,
are much smaller than the 1024 bytes a variable's value can hold),
and the unconditional NUL write at the end of get_token() then lands
outside the buffer too. Switch to snprintf(), which always leaves the
destination properly terminated, matching what the "undefined
variable" branch right below it already does.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tillkamppeter
tillkamppeter merged commit 288d696 into OpenPrinting:master Nov 19, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants