From 73d6722d2731009f933df654878137b0ff1563fd Mon Sep 17 00:00:00 2001 From: Kevin Lo Date: Sun, 16 May 2010 08:03:24 +0000 Subject: [PATCH] Use setresuid/setresgid to drop privileges --- sbin/bsdlabel/bsdlabel.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c index 9a6027c7951a..7f058747f246 100644 --- a/sbin/bsdlabel/bsdlabel.c +++ b/sbin/bsdlabel/bsdlabel.c @@ -684,6 +684,8 @@ editit(void) int pid, xpid; int locstat, omask; const char *ed; + uid_t uid; + gid_t gid; omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); while ((pid = fork()) < 0) { @@ -699,8 +701,12 @@ editit(void) } if (pid == 0) { sigsetmask(omask); - setgid(getgid()); - setuid(getuid()); + gid = getgid(); + if (setresgid(gid, gid, gid) == -1) + err(1, "setresgid"); + uid = getuid(); + if (setresuid(uid, uid, uid) == -1) + err(1, "setresuid"); if ((ed = getenv("EDITOR")) == (char *)0) ed = DEFEDITOR; execlp(ed, ed, tmpfil, (char *)0);