Skip to content

ppd-custom: guard ppdFindCustomOption() against a NULL keyword - #116

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/ppdfindcustomoption-null-keyword-deref
Nov 21, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/ppdfindcustomoption-null-keyword-deref

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Summary

ppdFindCustomOption() is the odd one out among this library's ppdFind*() lookup functions: every other one (ppdFindOption in ppd-mark.c, ppdFindAttr in ppd-attr.c, and the other three functions in this very file - ppdFindCustomParam, ppdFirstCustomParam, ppdNextCustomParam) checks every pointer argument before touching it. ppdFindCustomOption() only checked ppd, then called strlcpy(key.keyword, keyword, sizeof(key.keyword)) unconditionally.

strlcpy() calls strlen() on its source first, so a NULL keyword crashes. The existing test file's own comment even describes the guard as complete ("opens with a NULL guard... for ppdFindCustomOption"), without noticing it only covers ppd, not keyword.

Fix

Added || !keyword to the existing guard, matching the pattern already used by every sibling function in this file and in ppd-mark.c/ppd-attr.c.

Test plan

  • Added a regression test (T06b in test_ppd_custom.c) that calls ppdFindCustomOption(ppd, NULL) with a real, open PPD and asserts it returns NULL instead of crashing.
  • CI

Every other ppdFind*() lookup function in this library (ppdFindOption,
ppdFindAttr, and the other three functions in this very file) checks
both of its pointer arguments before use. ppdFindCustomOption() only
checked ppd, then called strlcpy(key.keyword, keyword, ...)
unconditionally - strlcpy() calls strlen() on keyword first, so a NULL
keyword crashes. Added the missing check and a regression test with a
real, open PPD.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 18:50

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 5f72619 into OpenPrinting:master Nov 21, 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