diff options
author | Christian Persch <chpe@src.gnome.org> | 2022-09-20 21:39:11 +0200 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2022-09-20 21:40:02 +0200 |
commit | 6e4b6455d1100c76ff1fc0b9481e230c82947117 (patch) | |
tree | c83fc379f5d8cc0c001f53bccb9ef4327544de2c /src | |
parent | b939bc12ce80bf5c8ce3d8b94d5b1a261efd4e72 (diff) | |
download | vte-6e4b6455d1100c76ff1fc0b9481e230c82947117.tar.gz |
app: Filter unwanted environment variables
(cherry picked from commit 391cd322f0c176d052da5417d3e372cf861c5b06)
Diffstat (limited to 'src')
-rw-r--r-- | src/app/app.cc | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/src/app/app.cc b/src/app/app.cc index 6ad12150..7488f2d3 100644 --- a/src/app/app.cc +++ b/src/app/app.cc @@ -157,6 +157,86 @@ public: return m_map_fds; } + auto environment_for_spawn() const noexcept + { + auto envv = g_get_environ(); + + // Merge in extra variables + if (environment) { + for (auto i = 0; environment[i]; ++i) { + auto const eq = strchr(environment[i], '='); + if (eq) { + auto const var = vte::glib::take_string(g_strndup(environment[i], eq - environment[i])); + envv = g_environ_setenv(envv, var.get(), eq + 1, true); + } else { + envv = g_environ_unsetenv(envv, environment[i]); + } + } + } + + // Cleanup environment + // List of variables and prefixes copied from gnome-terminal. + for (auto const& var : {"COLORTERM", + "COLUMNS", + "DESKTOP_STARTUP_ID", + "EXIT_CODE", + "EXIT_STATUS", + "GIO_LAUNCHED_DESKTOP_FILE", + "GIO_LAUNCHED_DESKTOP_FILE_PID", + "GJS_DEBUG_OUTPUT", + "GJS_DEBUG_TOPICS", + "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", + "SHLVL", + "TERM", + "VTE_VERSION", + "WATCHDOG_PID", + "WATCHDOG_USEC", + "WINDOWID"}) { + envv = g_environ_unsetenv(envv, var); + } + + for (auto const& prefix : {"GNOME_TERMINAL_", + + // other terminals + "FOOT_", + "ITERM2_", + "MC_", + "MINTTY_", + "PUTTY_", + "RXVT_", + "TERM_", + "URXVT_", + "WEZTERM_", + "XTERM_"}) { + for (auto i = 0; envv[i]; ++i) { + if (!g_str_has_prefix (envv[i], prefix)) + continue; + + auto const eq = strchr(envv[i], '='); + g_assert(eq); + auto const var = vte::glib::take_string(g_strndup(envv[i], eq - envv[i])); + envv = g_environ_unsetenv(envv, var.get()); + } + } + + return vte::glib::take_strv(envv); + } + private: std::vector<vte::libc::FD> m_fds{}; @@ -732,7 +812,7 @@ public: return rv; } -}; +}; // class Options Options options{}; /* global */ @@ -1684,6 +1764,7 @@ vteapp_window_launch_argv(VteappWindow* window, GError** error) { auto const spawn_flags = GSpawnFlags(G_SPAWN_SEARCH_PATH_FROM_ENVP | + VTE_SPAWN_NO_PARENT_ENVV | (options.no_systemd_scope ? VTE_SPAWN_NO_SYSTEMD_SCOPE : 0) | (options.require_systemd_scope ? VTE_SPAWN_REQUIRE_SYSTEMD_SCOPE : 0)); auto fds = options.fds(); @@ -1692,7 +1773,7 @@ vteapp_window_launch_argv(VteappWindow* window, VTE_PTY_DEFAULT, options.working_directory, argv, - options.environment, + options.environment_for_spawn().get(), fds.data(), fds.size(), map_fds.data(), map_fds.size(), spawn_flags, |