diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-09-03 13:29:53 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 10:19:06 +0100 |
commit | f2cfa6051c00fe07268bf72f625ba4b2cf21e168 (patch) | |
tree | e586c7542704905aadce9feb7c1e03b5202690a5 /src/basic/util.c | |
parent | 964936c4a45207552d6c3ead6d2c9bbd21d8028b (diff) |
util: add new uid_is_valid() call
This simply factors out the uid validation checks from parse_uid() and
uses them everywhere. This simply verifies that the passed UID is
neither 64bit -1 nor 32bit -1.
Diffstat (limited to 'src/basic/util.c')
-rw-r--r-- | src/basic/util.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/basic/util.c b/src/basic/util.c index 0d45b631f..473165f24 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -373,6 +373,19 @@ int parse_pid(const char *s, pid_t* ret_pid) { return 0; } +bool uid_is_valid(uid_t uid) { + + /* Some libc APIs use UID_INVALID as special placeholder */ + if (uid == (uid_t) 0xFFFFFFFF) + return false; + + /* A long time ago UIDs where 16bit, hence explicitly avoid the 16bit -1 too */ + if (uid == (uid_t) 0xFFFF) + return false; + + return true; +} + int parse_uid(const char *s, uid_t* ret_uid) { unsigned long ul = 0; uid_t uid; @@ -389,12 +402,7 @@ int parse_uid(const char *s, uid_t* ret_uid) { if ((unsigned long) uid != ul) return -ERANGE; - /* Some libc APIs use UID_INVALID as special placeholder */ - if (uid == (uid_t) 0xFFFFFFFF) - return -ENXIO; - - /* A long time ago UIDs where 16bit, hence explicitly avoid the 16bit -1 too */ - if (uid == (uid_t) 0xFFFF) + if (!uid_is_valid(uid)) return -ENXIO; if (ret_uid) |