From 1d4aa672424d8b1629fda11400b88607b5066965 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Mon, 19 Oct 2015 15:42:30 +0200 Subject: [PATCH] xorg-wrapper: when starting the server as root, reset its environment When the server is privileged, we shouldn't be passing the user's environment directly. Clearing the environment is recommended by the libdbus maintainers, see https://bugs.freedesktop.org/show_bug.cgi?id=52202 v2: rename envp to empty_envp (Jeremy) Reviewed-by: Hans de Goede Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=83849 Signed-off-by: Julien Cristau --- hw/xfree86/xorg-wrapper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/xorg-wrapper.c b/hw/xfree86/xorg-wrapper.c index 75d120ab6..6f658d7e2 100644 --- a/hw/xfree86/xorg-wrapper.c +++ b/hw/xfree86/xorg-wrapper.c @@ -194,6 +194,7 @@ int main(int argc, char *argv[]) int total_cards = 0; int allowed = CONSOLE_ONLY; int needs_root_rights = -1; + char *const empty_envp[1] = { NULL, }; progname = argv[0]; @@ -271,7 +272,10 @@ int main(int argc, char *argv[]) } argv[0] = buf; - (void) execv(argv[0], argv); + if (getuid() == geteuid()) + (void) execv(argv[0], argv); + else + (void) execve(argv[0], argv, empty_envp); fprintf(stderr, "%s: Failed to execute %s: %s\n", progname, buf, strerror(errno)); exit(1);