summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-26 00:38:21 +0100
committerLennart Poettering <lennart@poettering.net>2015-10-26 01:24:38 +0100
commit67c7c892b9fcb946792b380a30c4ba704c700934 (patch)
treea45c6dda9d2f1138dd3d8e075dce75a9e744a06a /src
parentd02608170e599b1ffbc7c9a22062bae2579d6e36 (diff)
user-util: never hand out or accept invalid UIDs
libc isn't that strict, but it's a good idea if we are, to not create confusion around invalid user ids.
Diffstat (limited to 'src')
-rw-r--r--src/basic/user-util.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index b5e6ce8a8a..7e6c4c645d 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -138,11 +138,19 @@ int get_user_creds(
if (!p)
return errno > 0 ? -errno : -ESRCH;
- if (uid)
+ if (uid) {
+ if (!uid_is_valid(p->pw_uid))
+ return -EBADMSG;
+
*uid = p->pw_uid;
+ }
+
+ if (gid) {
+ if (!gid_is_valid(p->pw_gid))
+ return -EBADMSG;
- if (gid)
*gid = p->pw_gid;
+ }
if (home)
*home = p->pw_dir;
@@ -185,8 +193,12 @@ int get_group_creds(const char **groupname, gid_t *gid) {
if (!g)
return errno > 0 ? -errno : -ESRCH;
- if (gid)
+ if (gid) {
+ if (!gid_is_valid(g->gr_gid))
+ return -EBADMSG;
+
*gid = g->gr_gid;
+ }
return 0;
}
@@ -278,6 +290,9 @@ int in_gid(gid_t gid) {
if (getegid() == gid)
return 1;
+ if (!gid_is_valid(gid))
+ return -EINVAL;
+
ngroups_max = sysconf(_SC_NGROUPS_MAX);
assert(ngroups_max > 0);