Repository navigation
fix invalid free of pdl_list entries in on_job_state - #90
Merged
tillkamppeter merged 1 commit intoNov 24, 2026
Merged
tillkamppeter merged 1 commit into
tillkamppeter merged 1 commit into
Conversation
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.
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
When picking the document format to hand a job to in
on_job_state(),pdl_listis a cupsArray withfree()as its destructor, but the entries added to it are never our own.The bug
When a
document-format-supportedattribute is available, entries areippGetString()values owned by the printer's ownprattrsIPP 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 callingfree()on memory it was never given ownership of - an interior pointer isn't even somethingmalloc()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 fromippGetString()instead of handing them tostrcasecmp.Test plan
upstream/master: the buggy line (cupsArrayAdd(pdl_list, (void *)format)) is unchanged, so the bug is still present and reachable exactly as described.