aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/spawn.c50
-rw-r--r--src/spawn.h2
2 files changed, 27 insertions, 25 deletions
diff --git a/src/spawn.c b/src/spawn.c
index b1cd305..507d1cd 100644
--- a/src/spawn.c
+++ b/src/spawn.c
@@ -118,7 +118,7 @@ teco_spawn_init(void)
#endif
}
-static gchar **
+gchar **
teco_parse_shell_command_line(const gchar *cmdline, GError **error)
{
gchar **argv;
@@ -142,7 +142,6 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error)
argv[2] = g_strdup("/c");
argv[3] = g_strdup(cmdline);
argv[4] = NULL;
- return argv;
}
#elif defined(G_OS_UNIX)
if (!(teco_ed & TECO_ED_SHELLEMU)) {
@@ -162,11 +161,33 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error)
argv[1] = g_strdup("-c");
argv[2] = g_strdup(cmdline);
argv[3] = NULL;
- return argv;
}
#endif
+ else if (!g_shell_parse_argv(cmdline, NULL, &argv, error))
+ return NULL;
+
+#if defined(__FreeBSD__) && __FreeBSD__ < 16
+ /*
+ * FIXME: g_spawn_async_with_pipes() will internally call
+ * posix_spawnp() which uses a tiny 4kb stack which can
+ * easily result in memory corruption if the path does not
+ * contain '/', ie. must be resolved against $PATH.
+ * See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295991
+ * As a workaround, only pass down absolute paths.
+ * This is not perfect: It will use $PATH from the environment,
+ * so you cannot overwrite it from within SciTECO.
+ */
+ gchar *program = g_find_program_in_path(argv[0]);
+ if (!program) {
+ g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
+ "Program \"%s\" not found", argv[0]);
+ return NULL;
+ }
+ g_free(argv[0]);
+ argv[0] = program;
+#endif /* __FreeBSD__ < 16 */
- return g_shell_parse_argv(cmdline, NULL, &argv, error) ? argv : NULL;
+ return argv;
}
static gboolean
@@ -296,27 +317,6 @@ teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **er
if (!argv)
goto gerror;
-#if defined(__FreeBSD__) && __FreeBSD__ < 16
- /*
- * FIXME: g_spawn_async_with_pipes() will internally call
- * posix_spawnp() which uses a tiny 4kb stack which can
- * easily result in memory corruption if the path does not
- * contain '/', ie. must be resolved against $PATH.
- * See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295991
- * As a workaround, only pass down absolute paths.
- * This is not perfect: It will use $PATH from the environment,
- * so you cannot overwrite it from within SciTECO.
- */
- gchar *program = g_find_program_in_path(argv[0]);
- if (!program) {
- g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
- "Program \"%s\" not found", argv[0]);
- goto gerror;
- }
- g_free(argv[0]);
- argv[0] = program;
-#endif /* __FreeBSD__ < 16 */
-
envp = teco_qreg_table_get_environ(&teco_qreg_table_globals, error);
if (!envp)
goto gerror;
diff --git a/src/spawn.h b/src/spawn.h
index 09764bd..5d2a5a4 100644
--- a/src/spawn.h
+++ b/src/spawn.h
@@ -18,5 +18,7 @@
#include "parser.h"
+gchar **teco_parse_shell_command_line(const gchar *cmdline, GError **error);
+
extern teco_state_t teco_state_execute;
extern teco_state_t teco_state_egcommand;