Date: Mon, 25 Apr 2011 10:14:29 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r221012 - head/bin/sh Message-ID: <201104251014.p3PAETAM070986@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Mon Apr 25 10:14:29 2011 New Revision: 221012 URL: http://svn.freebsd.org/changeset/base/221012 Log: sh: Check setuid()/setgid() return values. If the -p option is turned off, privileges from a setuid or setgid binary are dropped. Make sure to check if this succeeds. If it fails, this is an error which will cause the shell to abort except in interactive mode or if 'command' was used to make 'set' or an outer 'eval' or '.' non-special. Note that taking advantage of this feature and writing setuid shell scripts seems unwise. MFC after: 1 week Modified: head/bin/sh/options.c Modified: head/bin/sh/options.c ============================================================================== --- head/bin/sh/options.c Mon Apr 25 10:08:34 2011 (r221011) +++ head/bin/sh/options.c Mon Apr 25 10:14:29 2011 (r221012) @@ -280,8 +280,10 @@ setoption(int flag, int val) int i; if (flag == 'p' && !val && privileged) { - (void) setuid(getuid()); - (void) setgid(getgid()); + if (setgid(getgid()) == -1) + error("setgid"); + if (setuid(getuid()) == -1) + error("setuid"); } for (i = 0; i < NOPTS; i++) if (optlist[i].letter == flag) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104251014.p3PAETAM070986>