From d21c8fc44b0717bcc6076aea99277da169deb37e Mon Sep 17 00:00:00 2001 From: Jesse Smith Date: Tue, 20 Feb 2018 19:37:29 -0400 Subject: [PATCH] Perform error check on setuid() call in shutdown as manual page suggests. --- src/shutdown.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/shutdown.c b/src/shutdown.c index d9ac9f4..f85bc38 100644 --- a/src/shutdown.c +++ b/src/shutdown.c @@ -498,7 +498,15 @@ int main(int argc, char **argv) int user_ok = 0; /* We can be installed setuid root (executable for a special group) */ - setuid(geteuid()); + /* + This way is risky, do error check on setuid call. + setuid(geteuid()); + */ + errno = 0; + if (setuid(geteuid()) == -1) { + fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno)); + abort(); + } if (getuid() != 0) { fprintf(stderr, "shutdown: you must be root to do that!\n");