-/* $OpenBSD: uidswap.c,v 1.37 2015/01/16 06:40:12 deraadt Exp $ */
+/* $OpenBSD: uidswap.c,v 1.38 2015/06/22 12:29:57 dtucker Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
fatal("getgroups: %.100s", strerror(errno));
}
/* Set the effective uid to the given (unprivileged) uid. */
- if (setgroups(user_groupslen, user_groups) < 0)
+ if (user_groupslen > 0 && setgroups(user_groupslen, user_groups) < 0)
fatal("setgroups: %.100s", strerror(errno));
if (setegid(pw->pw_gid) < 0)
fatal("setegid %u: %.100s", (u_int)pw->pw_gid,
/* Set the effective uid back to the saved privileged uid. */
if (seteuid(saved_euid) < 0)
fatal("seteuid %u: %.100s", (u_int)saved_euid, strerror(errno));
- if (setgroups(saved_egroupslen, saved_egroups) < 0)
+ if (saved_egroupslen > 0 &&
+ setgroups(saved_egroupslen, saved_egroups) < 0)
fatal("setgroups: %.100s", strerror(errno));
if (setegid(saved_egid) < 0)
fatal("setegid %u: %.100s", (u_int)saved_egid, strerror(errno));