Skip to content

Commit

Permalink
main.c: fix non-root usage when installed suid root
Browse files Browse the repository at this point in the history
When toybox is installed suid root and invoked by a non-root user for
commands which do not require root privileges, it drops the root
privileges during initialization.

However, since commit afba5b8 the result check of setuid() was
inverted such that it aborted on success, making toybox unusuable for
non-root users.

Signed-off-by: Patrick Ohly <[email protected]>
  • Loading branch information
pohly authored and landley committed Feb 11, 2016
1 parent e2d042c commit 62b53ed
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void toy_init(struct toy_list *which, char *argv[])

if (!(which->flags & TOYFLAG_STAYROOT)) {
if (uid != euid) {
if (!setuid(uid)) perror_exit("setuid %d->%d", euid, uid); // drop root
if (setuid(uid)) perror_exit("setuid %d->%d", euid, uid); // drop root
euid = uid;
toys.wasroot++;
}
Expand Down

0 comments on commit 62b53ed

Please sign in to comment.