Repository navigation
Fix out-of-scope size name pointer in cups_create_media_db - #198
Open
tanjiroK-coder wants to merge 1 commit into
Open
tanjiroK-coder wants to merge 1 commit into
tanjiroK-coder wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
cups_create_media_db builds a media key for each media-col-database (or media-col-ready) entry that has no media-key. When the entry also lacks media-size-name it asks _pwgMediaNearSize for a name, passing a keyword buffer that is declared inside the enclosing if block, and then points mdb.size_name at that buffer. For a standard size _pwgMediaNearSize returns the static table entry without writing keyword, so size_name points at uninitialized stack, and in every case the pointer outlives the block, so cupsArrayAdd copies the entry at the end of the loop from an out-of-scope buffer. I hit this with a printer whose media-col-database carried media-size and media-source but no media-key or media-size-name, which is legal IPP: AddressSanitizer reports stack-use-after-scope at dest-options.c:1885, and without the sanitizer the garbage becomes the media name handed out by cupsGetDestMedia* and sent back to the printer as the media attribute. The attributes come from the printer, so any client calling cupsGetDestMediaByIndex, cupsGetDestMediaByName, cupsGetDestMediaBySize, cupsGetDestMediaDefault, cupsGetDestMediaCount, cupsLocalizeDestMedia or cupsAddDestMediaOptions is exposed. The fix moves temppwg, keyword and ppdname to function scope and takes the size name from the pwg_media_t that _pwgMediaNearSize returns, which is either the table string or keyword, the same way cupsGetDestMediaByName already does. Media names for entries that carry media-key or media-size-name are unchanged.
Proposed changelog entry:
cups_create_media_dbwhen a printer omits "media-key" and "media-size-name".