[gdm] gdm-{wayland, x}-session: only omit unset session variables from environment



commit cc7c9dc0d4a7512b641b2b3ffe2a9b651880bdbf
Author: Ray Strode <rstrode redhat com>
Date:   Mon Aug 7 14:26:08 2017 +0800

    gdm-{wayland,x}-session: only omit unset session variables from environment
    
    The display server launcher wrapper scripts try to unset any stale
    environment variables imported from systemd.
    
    There is a possibility, some of these stale variables, however, could be
    "refreshed" by gdm in the current session.  If that's the case, we
    shouldn't clear them.
    
    This reworks the unset calls into a loop, and guards each unset call
    with a check to make sure it's not in the current environment.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785918

 daemon/gdm-wayland-session.c |   19 +++++++++++++------
 daemon/gdm-x-session.c       |   19 ++++++++++++++++---
 2 files changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/daemon/gdm-wayland-session.c b/daemon/gdm-wayland-session.c
index efdb34e..af79608 100644
--- a/daemon/gdm-wayland-session.c
+++ b/daemon/gdm-wayland-session.c
@@ -280,6 +280,11 @@ spawn_session (State        *state,
         gboolean             is_running = FALSE;
         int                  ret;
         char               **argv = NULL;
+        static const char  *session_variables[] = { "DISPLAY",
+                                                    "XAUTHORITY",
+                                                    "WAYLAND_DISPLAY",
+                                                    "WAYLAND_SOCKET",
+                                                    NULL };
 
         g_debug ("Running wayland session");
 
@@ -313,18 +318,20 @@ spawn_session (State        *state,
 
                         g_subprocess_launcher_setenv (launcher, environment_entry[0], environment_entry[1], 
FALSE);
                 }
+
+                /* Don't allow session specific environment variables from earlier sessions to
+                 * leak through */
+                for (i = 0; session_variables[i] != NULL; i++) {
+                        if (g_getenv (session_variables[i]) == NULL) {
+                                g_subprocess_launcher_unsetenv (launcher, session_variables[i]);
+                        }
+                }
         }
 
         if (state->bus_address != NULL) {
                 g_subprocess_launcher_setenv (launcher, "DBUS_SESSION_BUS_ADDRESS", state->bus_address, 
TRUE);
         }
 
-        /* Don't allow session specific environment variables from earlier sessions to leak through */
-        g_subprocess_launcher_unsetenv (launcher, "DISPLAY");
-        g_subprocess_launcher_unsetenv (launcher, "XAUTHORITY");
-        g_subprocess_launcher_unsetenv (launcher, "WAYLAND_DISPLAY");
-        g_subprocess_launcher_unsetenv (launcher, "WAYLAND_SOCKET");
-
         subprocess = g_subprocess_launcher_spawnv (launcher,
                                                    (const char * const *) argv,
                                                    &error);
diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c
index b919e6e..b5c0d20 100644
--- a/daemon/gdm-x-session.c
+++ b/daemon/gdm-x-session.c
@@ -605,14 +605,16 @@ spawn_session (State        *state,
         GError              *error = NULL;
         gboolean             is_running = FALSE;
         const char          *vt;
+        static const char   *session_variables[] = { "DISPLAY",
+                                                     "XAUTHORITY",
+                                                     "WAYLAND_DISPLAY",
+                                                     "WAYLAND_SOCKET",
+                                                     NULL };
 
         g_debug ("Running X session");
 
         launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
 
-        g_subprocess_launcher_setenv (launcher, "DISPLAY", state->display_name, TRUE);
-        g_subprocess_launcher_setenv (launcher, "XAUTHORITY", state->auth_file, TRUE);
-
         if (state->environment != NULL) {
                 size_t i;
 
@@ -631,8 +633,19 @@ spawn_session (State        *state,
 
                         g_subprocess_launcher_setenv (launcher, environment_entry[0], environment_entry[1], 
FALSE);
                 }
+
+                /* Don't allow session specific environment variables from earlier sessions to
+                 * leak through */
+                for (i = 0; session_variables[i] != NULL; i++) {
+                        if (g_getenv (session_variables[i]) == NULL) {
+                                g_subprocess_launcher_unsetenv (launcher, session_variables[i]);
+                        }
+                }
         }
 
+        g_subprocess_launcher_setenv (launcher, "DISPLAY", state->display_name, TRUE);
+        g_subprocess_launcher_setenv (launcher, "XAUTHORITY", state->auth_file, TRUE);
+
         if (state->bus_address != NULL) {
                 g_subprocess_launcher_setenv (launcher, "DBUS_SESSION_BUS_ADDRESS", state->bus_address, 
TRUE);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]