[vte] spawn: Add envv precondition check
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] spawn: Add envv precondition check
- Date: Fri, 1 May 2020 08:21:32 +0000 (UTC)
commit 9697d30cead63dfba031d3547140668535395540
Author: Christian Persch <chpe src gnome org>
Date: Fri May 1 10:21:16 2020 +0200
spawn: Add envv precondition check
Make sure the passed environment contains valid entries in the KEY=VALUE format.
src/vtegtk.cc | 1 +
src/vtepty.cc | 23 +++++++++++++++++++++++
src/vteptyinternal.hh | 2 ++
3 files changed, 26 insertions(+)
---
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index af32a166..8b14e697 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2792,6 +2792,7 @@ vte_terminal_spawn_sync(VteTerminal *terminal,
g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
g_return_val_if_fail(argv != NULL, FALSE);
g_return_val_if_fail(argv[0] != nullptr, FALSE);
+ g_return_val_if_fail(envv == nullptr ||_vte_pty_check_envv(envv), false);
g_return_val_if_fail((spawn_flags & (VTE_SPAWN_NO_SYSTEMD_SCOPE | VTE_SPAWN_REQUIRE_SYSTEMD_SCOPE))
== 0, FALSE);
g_return_val_if_fail(child_setup_data == NULL || child_setup, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
diff --git a/src/vtepty.cc b/src/vtepty.cc
index edd9d0bc..7d52ab95 100644
--- a/src/vtepty.cc
+++ b/src/vtepty.cc
@@ -640,6 +640,28 @@ _vte_pty_spawn_sync(VtePty* pty,
return rv;
}
+/*
+ * _vte_pty_check_envv:
+ * @strv:
+ *
+ * Validates that each element is of the form 'KEY=VALUE'.
+ */
+bool
+_vte_pty_check_envv(char const* const* strv)
+{
+ if (!strv)
+ return true;
+
+ char const *p;
+ while ((p = *strv++))
+ {
+ if (!strchr(p, '='))
+ return false;
+ }
+
+ return true;
+}
+
/**
* vte_pty_spawn_with_fds_async:
* @pty: a #VtePty
@@ -715,6 +737,7 @@ vte_pty_spawn_with_fds_async(VtePty *pty,
{
g_return_if_fail(argv != nullptr);
g_return_if_fail(argv[0] != nullptr);
+ g_return_if_fail(envv == nullptr || _vte_pty_check_envv(envv));
g_return_if_fail(n_fds == 0 || fds != nullptr);
for (auto i = int{0}; i < n_fds; ++i)
g_return_if_fail(vte::libc::fd_get_cloexec(fds[i]));
diff --git a/src/vteptyinternal.hh b/src/vteptyinternal.hh
index 14321008..7e1a8b5d 100644
--- a/src/vteptyinternal.hh
+++ b/src/vteptyinternal.hh
@@ -34,3 +34,5 @@ bool _vte_pty_spawn_sync(VtePty* pty,
int timeout,
GCancellable* cancellable,
GError** error);
+
+bool _vte_pty_check_envv(char const* const* envv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]