Skip to content

ppd-collection: check malloc before copying into it - #117

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/ppd-collection-listppds-unchecked-malloc
Nov 21, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/ppd-collection-listppds-unchecked-malloc

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Summary

Two spots in ppd-collection.cxx allocate a small record with malloc() and immediately memcpy() into the result without checking for NULL:

  • ppdCollectionListPPDs(), when copying a matched PPD record for the caller.
  • load_ppds()'s directory-loop-detection bookkeeping.

Both are on the normal path of listing/scanning a PPD collection (e.g. cups-driverd list on a Printer Application's PPD database), so an allocation failure there is currently a NULL-pointer memcpy rather than a clean error.

Fix

  • ppdCollectionListPPDs(): on failure, log and stop adding further PPDs to the result array it already built (returning what it has so far rather than crashing).
  • load_ppds(): on failure, log and return failure, since it can no longer safely track this directory for loop detection.

Both follow the existing calloc(...) == NULL error-logging pattern already used elsewhere in this same file.

Test plan

  • CI

Two spots allocate a small record with malloc() and immediately
memcpy() into the result without checking for NULL:
ppdCollectionListPPDs() when copying a matched PPD record for the
caller, and load_ppds()'s directory-loop-detection bookkeeping. Both
are on the normal path of listing/scanning a PPD collection (e.g.
"cups-driverd list" on a Printer Application's PPD database), so an
allocation failure there is currently a NULL-pointer memcpy rather
than a clean error.

ppdCollectionListPPDs() logs and stops adding further PPDs to the
result it already built; load_ppds() logs and returns failure, since
it can no longer safely track this directory for loop detection.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 19:01

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 fe1369b 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