[gnome-terminal] server: Filter environment variables in the server too
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] server: Filter environment variables in the server too
- Date: Fri, 25 Dec 2020 17:01:52 +0000 (UTC)
commit 8979ac4cbfbaa11237ddaf5132393f6a99d0c6ea
Author: Christian Persch <chpe src gnome org>
Date: Fri Dec 25 18:01:12 2020 +0100
server: Filter environment variables in the server too
src/Makefile.am | 2 ++
src/terminal-client-utils.c | 88 ++++++++++++++++++++++++++++++---------------
src/terminal-client-utils.h | 6 +++-
src/terminal-screen.c | 19 +++-------
4 files changed, 72 insertions(+), 43 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ea3d930..4583cfcb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,6 +45,8 @@ gnome_terminal_server_SOURCES = \
terminal-accels.h \
terminal-app.c \
terminal-app.h \
+ terminal-client-utils.c \
+ terminal-client-utils.h \
terminal-debug.c \
terminal-debug.h \
terminal-defines.h \
diff --git a/src/terminal-client-utils.c b/src/terminal-client-utils.c
index e9292810..55f56ab3 100644
--- a/src/terminal-client-utils.c
+++ b/src/terminal-client-utils.c
@@ -99,6 +99,65 @@ terminal_client_append_create_instance_options (GVariantBuilder *builder,
"fullscreen-window", g_variant_new_boolean (TRUE));
}
+char const* const*
+terminal_client_get_environment_filters (void)
+{
+ static char const* filters[] = {
+ "COLORTERM",
+ "COLUMNS",
+ "DESKTOP_STARTUP_ID",
+ "EXIT_CODE",
+ "EXIT_STATUS",
+ "GIO_LAUNCHED_DESKTOP_FILE",
+ "GIO_LAUNCHED_DESKTOP_FILE_PID",
+ "GNOME_DESKTOP_ICON",
+ "INVOCATION_ID",
+ "JOURNAL_STREAM",
+ "LINES",
+ "LISTEN_FDNAMES",
+ "LISTEN_FDS",
+ "LISTEN_PID",
+ "MAINPID",
+ "MANAGERPID",
+ "NOTIFY_SOCKET",
+ "NOTIFY_SOCKET",
+ "PIDFILE",
+ "PWD",
+ "REMOTE_ADDR",
+ "REMOTE_PORT",
+ "SERVICE_RESULT",
+ "TERM",
+ "VTE_VERSION",
+ "WATCHDOG_PID",
+ "WATCHDOG_USEC",
+ "WINDOWID",
+ NULL
+ };
+
+ return filters;
+}
+
+/**
+ * terminal_client_filter_environment:
+ * @envv: (transfer full): the environment
+ *
+ * Filters unwanted variables from @envv, and returns it.
+ *
+ * Returns: (transfer full): the filtered environment
+ */
+char**
+terminal_client_filter_environment (char** envv)
+{
+ if (envv == NULL)
+ return NULL;
+
+ char const* const* filters = terminal_client_get_environment_filters ();
+ for (unsigned i = 0; filters[i]; ++i)
+ envv = g_environ_unsetenv (envv, filters[i]);
+
+ return envv;
+}
+
/**
* terminal_client_append_exec_options:
* @builder: a #GVariantBuilder of #GVariantType "a{sv}"
@@ -122,34 +181,7 @@ terminal_client_append_exec_options (GVariantBuilder *builder,
gs_strfreev char **envv;
envv = g_get_environ ();
- envv = g_environ_unsetenv (envv, "COLORTERM");
- envv = g_environ_unsetenv (envv, "COLUMNS");
- envv = g_environ_unsetenv (envv, "DESKTOP_STARTUP_ID");
- envv = g_environ_unsetenv (envv, "EXIT_CODE");
- envv = g_environ_unsetenv (envv, "EXIT_STATUS");
- envv = g_environ_unsetenv (envv, "GIO_LAUNCHED_DESKTOP_FILE");
- envv = g_environ_unsetenv (envv, "GIO_LAUNCHED_DESKTOP_FILE_PID");
- envv = g_environ_unsetenv (envv, "GNOME_DESKTOP_ICON");
- envv = g_environ_unsetenv (envv, "INVOCATION_ID");
- envv = g_environ_unsetenv (envv, "JOURNAL_STREAM");
- envv = g_environ_unsetenv (envv, "LINES");
- envv = g_environ_unsetenv (envv, "LISTEN_FDNAMES");
- envv = g_environ_unsetenv (envv, "LISTEN_FDS");
- envv = g_environ_unsetenv (envv, "LISTEN_PID");
- envv = g_environ_unsetenv (envv, "MAINPID");
- envv = g_environ_unsetenv (envv, "MANAGERPID");
- envv = g_environ_unsetenv (envv, "NOTIFY_SOCKET");
- envv = g_environ_unsetenv (envv, "NOTIFY_SOCKET");
- envv = g_environ_unsetenv (envv, "PIDFILE");
- envv = g_environ_unsetenv (envv, "PWD");
- envv = g_environ_unsetenv (envv, "REMOTE_ADDR");
- envv = g_environ_unsetenv (envv, "REMOTE_PORT");
- envv = g_environ_unsetenv (envv, "SERVICE_RESULT");
- envv = g_environ_unsetenv (envv, "TERM");
- envv = g_environ_unsetenv (envv, "VTE_VERSION");
- envv = g_environ_unsetenv (envv, "WATCHDOG_PID");
- envv = g_environ_unsetenv (envv, "WATCHDOG_USEC");
- envv = g_environ_unsetenv (envv, "WINDOWID");
+ envv = terminal_client_filter_environment (envv);
envv = g_environ_unsetenv (envv, TERMINAL_ENV_SERVICE_NAME);
envv = g_environ_unsetenv (envv, TERMINAL_ENV_SCREEN);
diff --git a/src/terminal-client-utils.h b/src/terminal-client-utils.h
index 0a70637a..19a0a2b7 100644
--- a/src/terminal-client-utils.h
+++ b/src/terminal-client-utils.h
@@ -47,7 +47,11 @@ void terminal_client_append_exec_options (GVariantBuilder *builder,
gsize fd_array_len,
gboolean shell);
-char * terminal_client_get_fallback_startup_id (void);
+char * terminal_client_get_fallback_startup_id (void) G_GNUC_MALLOC;
+
+char const* const* terminal_client_get_environment_filters (void);
+
+char** terminal_client_filter_environment (char** envv) G_GNUC_MALLOC;
G_END_DECLS
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index f44de43a..464ed3b9 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -21,6 +21,7 @@
#include "terminal-pcre2.h"
#include "terminal-regex.h"
#include "terminal-screen.h"
+#include "terminal-client-utils.h"
#include <errno.h>
#include <string.h>
@@ -1453,20 +1454,10 @@ terminal_screen_get_child_environment (TerminalScreen *screen,
}
}
- g_hash_table_remove (env_table, "COLUMNS");
- g_hash_table_remove (env_table, "LINES");
- g_hash_table_remove (env_table, "GNOME_DESKTOP_ICON");
-
- /* WINDOWID does not work correctly ever since we don't use a native
- * GdkWindow anymore, and it also becomes incorrect if the screen is
- * moved to a different window, or the window unrealized and re-realized.
- * Additionally, it cannot ever work on non-X11 displays like wayland.
- * And on X11, the only use for this is broken foreign drawing on the
- * window (w3m etc), and trying to find the focused screen (brltty),
- * which can now be done correctly using DECSET 1004.
- * Therefore we do not set WINDOWID, and remove an existing variable.
- */
- g_hash_table_remove (env_table, "WINDOWID");
+ /* Remove unwanted env variables */
+ char const* const* filters = terminal_client_get_environment_filters ();
+ for (i = 0; filters[i]; ++i)
+ g_hash_table_remove (env_table, filters[i]);
terminal_util_add_proxy_env (env_table);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]