From 54efa54c0e732c3af964b7bc809cb309a2d53d7d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 31 Jul 2016 18:47:36 -0600 Subject: [PATCH] Only check SUDO_USER if euid is 0 --- plugins/sudoers/visudo.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 5ee96ee7a..3e9ecdce4 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) { struct sudoersfile *sp; - char *user, *editor, **editor_argv; + char *editor, **editor_argv; int ch, oldlocale, editor_argc, exitcode = 0; bool quiet, strict, oldperms; const char *export_path; @@ -215,9 +215,11 @@ main(int argc, char *argv[]) /* Mock up a fake sudo_user struct. */ user_cmnd = user_base = ""; - user = getenv("SUDO_USER"); - if (user != NULL && *user != '\0') - sudo_user.pw = sudo_getpwnam(user); + if (geteuid() == 0) { + const char *user = getenv("SUDO_USER"); + if (user != NULL && *user != '\0') + sudo_user.pw = sudo_getpwnam(user); + } if (sudo_user.pw == NULL) { if ((sudo_user.pw = sudo_getpwuid(getuid())) == NULL) sudo_fatalx(U_("you do not exist in the %s database"), "passwd"); -- 2.40.0