uid-range: add uid_range_overlaps() helper

This commit is contained in:
Lennart Poettering
2024-04-06 16:08:23 +02:00
parent 2251e4ef90
commit 5bff40e719
2 changed files with 22 additions and 0 deletions
+20
View File
@@ -253,3 +253,23 @@ int uid_range_load_userns(UIDRange **ret, const char *path) {
*ret = TAKE_PTR(range);
return 0;
}
bool uid_range_overlaps(const UIDRange *range, uid_t start, uid_t nr) {
if (!range)
return false;
/* Avoid overflow */
if (start > UINT32_MAX - nr)
nr = UINT32_MAX - start;
if (nr == 0)
return false;
FOREACH_ARRAY(entry, range->entries, range->n_entries)
if (start < entry->start + entry->nr &&
start + nr >= entry->start)
return true;
return false;
}
+2
View File
@@ -34,3 +34,5 @@ static inline bool uid_range_contains(const UIDRange *range, uid_t uid) {
int uid_map_read_one(FILE *f, uid_t *ret_base, uid_t *ret_shift, uid_t *ret_range);
int uid_range_load_userns(UIDRange **ret, const char *path);
bool uid_range_overlaps(const UIDRange *range, uid_t start, uid_t nr);