Skip to content

fix invalid free of pdl_list entries in on_job_state - #90

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-jobstate-pdl-list-invalid-free
Nov 24, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-jobstate-pdl-list-invalid-free

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Summary

When picking the document format to hand a job to in on_job_state(), pdl_list is a cupsArray with free() as its destructor, but the entries added to it are never our own.

The bug

When a document-format-supported attribute is available, entries are ippGetString() values owned by the printer's own prattrs IPP message. When falling back to the DNS-SD "pdl" string, entries are pointers into the middle of that one string (format is walked forward token by token, nothing is copied out). Either way, cupsArrayDelete(pdl_list) ends up calling free() on memory it was never given ownership of - an interior pointer isn't even something malloc() returned, so this is corruption waiting to happen, and it runs on every job sent to an implicit-class/cluster queue.

Fix

Store a strdup() of each format string instead, and skip NULL results from ippGetString() instead of handing them to strcasecmp.

Test plan

  • Code-traced against current upstream/master: the buggy line (cupsArrayAdd(pdl_list, (void *)format)) is unchanged, so the bug is still present and reachable exactly as described.

When picking the document format to hand a job to in on_job_state(),
pdl_list is a cupsArray with free() as its destructor, but the
entries added to it are never our own: when a document-format-
supported attribute is available they're ippGetString() values owned
by the printer's own prattrs IPP message, and when we fall back to
the DNS-SD "pdl" string they're pointers into the *middle* of that one
string (format is walked forward token by token, nothing is copied
out). Either way, cupsArrayDelete(pdl_list) ends up calling free() on
memory it was never given ownership of -- an interior pointer isn't
even something malloc() returned, so this is corruption waiting to
happen, and it runs on every job sent to an implicit-class/cluster
queue. Store a strdup() of each format string instead, and skip NULL
results from ippGetString() instead of handing them to strcasecmp.
Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:53

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 d945a2b into OpenPrinting:master Nov 24, 2026
11 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