Skip to content

fix argument quoting in win32_escape_dup for ippfind --exec - #212

Open
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ippfind-win32-arg-quoting
Open

tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ippfind-win32-arg-quoting

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

Trailing backslash escapes the closing quote in win32_escape_dup

On Windows, ippfind --exec quotes each argument with win32_escape_dup() before _spawnvpe(), but a backslash at the end of a value is copied as-is, so the C runtime reads it plus the closing quote as a literal " and the argument never ends. Substituted values such as {service_name} and {txt_KEY} come from DNS-SD advertisements, so a printer on the local network can make the following argument split into extra argv entries. The rewrite follows the MSVCRT rule: N backslashes before a quote or the closing quote become 2N, and " is written as \".

Repro (child prints the argv it receives), values x\ and --injected -o evil:

before: [x" --injected] [-o] [evil]
after:  [x\] [--injected -o evil]

The old code also turned \\server\share into \\\\server\share. A round-trip harness over 310 fixed and random inputs (quotes, backslashes, spaces) fails on most of them before and passes all of them after, with ASan enabled. The change is inside #if _WIN32, so other platforms build the same code as before.

This branch has not been deployed

No deployments
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.

1 participant