mirror of
https://github.com/systemd/systemd.git
synced 2024-11-24 10:43:35 +08:00
parse-util: rewrite parse_uid_range() on top of parse_uid()
parse_uid() does so many safety checks we want, hence rewrite parse_uid_range() on top of parse_uid() instead of parse_range().
This commit is contained in:
parent
f5979b63cc
commit
60eb1f0728
@ -74,22 +74,39 @@ int parse_uid(const char *s, uid_t *ret) {
|
||||
}
|
||||
|
||||
int parse_uid_range(const char *s, uid_t *ret_lower, uid_t *ret_upper) {
|
||||
uint32_t u, l;
|
||||
_cleanup_free_ char *word = NULL;
|
||||
uid_t l, u;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(ret_lower);
|
||||
assert(ret_upper);
|
||||
|
||||
r = parse_range(s, &l, &u);
|
||||
r = extract_first_word(&s, &word, "-", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
return -EINVAL;
|
||||
|
||||
r = parse_uid(word, &l);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (l > u)
|
||||
/* Check for the upper bound and extract it if needed */
|
||||
if (!s)
|
||||
/* Single number with no dash. */
|
||||
u = l;
|
||||
else if (!*s)
|
||||
/* Trailing dash is an error. */
|
||||
return -EINVAL;
|
||||
else {
|
||||
r = parse_uid(s, &u);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!uid_is_valid(l) || !uid_is_valid(u))
|
||||
return -ENXIO;
|
||||
if (l > u)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*ret_lower = l;
|
||||
*ret_upper = u;
|
||||
|
Loading…
Reference in New Issue
Block a user