Repository navigation
ppd-custom: guard ppdFindCustomOption() against a NULL keyword - #116
Merged
tillkamppeter merged 1 commit intoNov 21, 2026
Conversation
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.
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.
Summary
ppdFindCustomOption()is the odd one out among this library'sppdFind*()lookup functions: every other one (ppdFindOptioninppd-mark.c,ppdFindAttrinppd-attr.c, and the other three functions in this very file -ppdFindCustomParam,ppdFirstCustomParam,ppdNextCustomParam) checks every pointer argument before touching it.ppdFindCustomOption()only checkedppd, then calledstrlcpy(key.keyword, keyword, sizeof(key.keyword))unconditionally.strlcpy()callsstrlen()on its source first, so a NULLkeywordcrashes. The existing test file's own comment even describes the guard as complete ("opens with a NULL guard... for ppdFindCustomOption"), without noticing it only coversppd, notkeyword.Fix
Added
|| !keywordto the existing guard, matching the pattern already used by every sibling function in this file and inppd-mark.c/ppd-attr.c.Test plan
T06bintest_ppd_custom.c) that callsppdFindCustomOption(ppd, NULL)with a real, open PPD and asserts it returns NULL instead of crashing.