dvi-document: Use g_spawn_sync with argv instead of cmdline string - #725
Closed
yuri-schmaltz wants to merge 1 commit into
Closed
dvi-document: Use g_spawn_sync with argv instead of cmdline string#725yuri-schmaltz wants to merge 1 commit into
yuri-schmaltz wants to merge 1 commit into
Conversation
When exporting a DVI document to PDF, the previous code built a command-line string with g_strdup_printf() and ran it through g_spawn_command_line_sync(), which routes the string through /bin/sh -c. The argument values came from three places: * exporter_opts->str: built from page indices, low risk in practice * exporter_filename: chosen by the user in the export file dialog * context->filename: the path of the opened DVI document While the user-supplied values were shell-quoted with g_shell_quote(), this is the same fragile pattern that was recently patched in ev_spawn (commit 50052ea) and that the print previewer path also used. Build the argv[] array directly instead: argv = { dvipdfm, -s, <pages>, -o, exporter_filename, context->filename, NULL } The "-s <pages>" pair is split from exporter_opts and the trailing comma appended by do_page() is stripped, so dvipdfm receives the pages list as a single argument exactly as it would have through the shell. No shell, no tokenizer on our side: each element is forwarded verbatim to the child.
Author
|
Closing: this fix will live in the author's personal fork (yuri-schmaltz/xreader) as part of a fork-only maintenance workflow. The branches |
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 exporting a DVI document to PDF, the DVI backend ran
dvipdfmthroughg_spawn_command_line_sync(), which routes the command string through/bin/sh -c. The argument values came from three places:exporter_opts->str: built from page indices, low risk in practiceexporter_filename: chosen by the user in the export file dialogcontext->filename: the path of the opened DVI documentWhile the user-supplied values were shell-quoted with
g_shell_quote(), this is the same fragile pattern that was recently patched inev_spawn(commit 50052ea) and that the print previewer path also used. Build theargv[]array directly instead.What changes
g_spawn_command_line_sync(command_line)->g_spawn_sync(NULL, argv, NULL, 0, ...)-s <pages>pair is split fromexporter_optsand the trailing comma appended bydo_page()is stripped, sodvipdfmreceives the pages list as a single argument exactly as it would have through the shellBehavior preserved
dvipdfm)g_shell_quote()output of each arg)WIFEXITED/WEXITSTATUSchecks still work)Why this matters
The
ev_spawnfix in 50052ea (May 2026) only addedg_shell_quote()to the page label / named destination / search string arguments. That is defense-in-depth for one specific call site. This DVI path was missed -- it never hadg_shell_quote()applied toexporter_optsorexporter_filename, so a DVI document that lives at a path containing shell metacharacters (or a user who picks an output path with$(...)in it) would have those characters interpreted by/bin/shtoday.Test plan
meson setup build && meson compile -C build-- clean build.dvifile, File -> Export To -> PDF, choose a path with spaces and special chars in it -- export succeeds, output PDF is correctdvipdfmreceives-sand the comma-separated page list as separate args (run withstrace -f -e execveif needed)Diff stat