Repository navigation
dest.c: stop cups_dnssd_unquote() reading past a trailing backslash - #224
Open
ManasBagul23 wants to merge 1 commit into
Open
ManasBagul23 wants to merge 1 commit into
ManasBagul23 wants to merge 1 commit into
Conversation
cups_dnssd_unquote() unescapes a DNS-SD service name in place. When the name has a literal backslash as its very last character (nothing follows it before the terminating NUL), the function advances past the backslash with "src++" and unconditionally does "*dst++ = *src++" without checking whether that landed on the NUL. This copies the NUL into the destination (prematurely truncating the unescaped name) and advances src one byte past the string's own allocation; the loop's own "while (*src ...)" condition then dereferences that out-of-bounds byte. This function is reached directly from DNS-SD/mDNS discovery callbacks (cups_dest_query_cb(), cups_dest_browse_cb(), cups_dest_resolve()) on attacker-influenceable network data: any device on the local network broadcasting a service name ending in an unescaped backslash reaches this path. Reproduced the exact one-byte overread with a guard-page test (placing the string so its trailing NUL sits on the last byte of a mapped page, with the following page unmapped): the unpatched function reliably segfaults; the fixed version returns cleanly, treating the trailing backslash as having nothing left to unescape. Only copy the byte after the backslash when there is one.
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.
Summary
`cups_dnssd_unquote()` unescapes a DNS-SD service name in place.
The bug
When the name has a literal backslash as its very last character (nothing follows it before the terminating NUL), the function advances past the backslash with `src++` and unconditionally does `*dst++ = *src++` without checking whether that landed on the NUL. This copies the NUL into the destination (prematurely truncating the unescaped name) and advances `src` one byte past the string's own allocation; the loop's own `while (*src ...)` condition then dereferences that out-of-bounds byte.
This function is reached directly from DNS-SD/mDNS discovery callbacks (`cups_dest_query_cb()`, `cups_dest_browse_cb()`, `cups_dest_resolve()`) on attacker-influenceable network data: any device on the local network broadcasting a service name ending in an unescaped backslash reaches this path.
Fix
Only copy the byte after the backslash when there is one.
Test plan