Skip to content

Fix shell command safety: replace popen() with g_spawn functions#1314

Merged
karlkleinpaste merged 1 commit into
crosswire:masterfrom
lggcs:sec
May 22, 2026
Merged

Fix shell command safety: replace popen() with g_spawn functions#1314
karlkleinpaste merged 1 commit into
crosswire:masterfrom
lggcs:sec

Conversation

@lggcs
Copy link
Copy Markdown
Contributor

@lggcs lggcs commented May 19, 2026

Replace two popen() calls with GLib's g_spawn_async() and g_spawn_sync() to avoid passing arguments through a shell. This prevents filenames or other data containing shell metacharacters from being interpreted as shell commands.

  • src/main/url.cc show_separate_image(): use g_spawn_async() with an argument array and G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL flags, matching the original redirect-to-devnull behavior. Report errors via GError.

  • src/gtk/menu_popup.c on_rename_perscomm_activate(): use g_spawn_sync() with sed invoked via argument array. Capture stdout and write the result via g_file_set_contents(). Check exit status and GError.

Replace two popen() calls with GLib's g_spawn_async() and g_spawn_sync()
to avoid passing arguments through a shell. This prevents filenames or
other data containing shell metacharacters from being interpreted as
shell commands.

- src/main/url.cc show_separate_image(): use g_spawn_async() with an
  argument array and G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL
  flags, matching the original redirect-to-devnull behavior. Report errors
  via GError.

- src/gtk/menu_popup.c on_rename_perscomm_activate(): use g_spawn_sync()
  with sed invoked via argument array. Capture stdout and write the result
  via g_file_set_contents(). Check exit status and GError.
@lggcs
Copy link
Copy Markdown
Contributor Author

lggcs commented May 19, 2026

@karlkleinpaste If you have a private way of contacting you I can share additional information about this fix and impact. Thank you.

@karlkleinpaste
Copy link
Copy Markdown
Contributor

@lggcs my email is my name k...@k..........org, fill in the dots.

@karlkleinpaste karlkleinpaste merged commit f96ad32 into crosswire:master May 22, 2026
7 checks passed
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.

2 participants