summaryrefslogtreecommitdiffstats
path: root/debian/patches/server-Filter-environment-variables-in-the-server-too.patch
blob: 8e61b61fff7651e15f0a7911ff52abd340116138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
From: Christian Persch <chpe@src.gnome.org>
Date: Fri, 25 Dec 2020 18:01:12 +0100
Subject: server: Filter environment variables in the server too

Origin: upstream, 3.39.0, commit:8979ac4cbfbaa11237ddaf5132393f6a99d0c6ea
---
 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 2ea3d93..4583cfc 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 e929281..55f56ab 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 0a70637..19a0a2b 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 0c4ee50..0e447ae 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>
@@ -1455,20 +1456,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);