]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
subids: find_free_range(): skip empty ranges
authorHadi Chokr <hadichokr@icloud.com>
Thu, 9 Jul 2026 13:28:41 +0000 (13:28 +0000)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Fri, 10 Jul 2026 10:36:17 +0000 (12:36 +0200)
Empty (count == 0) ranges constrain nothing, so skip them instead of
processing them.  Besides documenting that invariant, this keeps the
range-end computation, first - 1LL + range->count, away from the
count == 0 corner, where for first == 0 it would produce -1 through
unsigned long wrap-around and an implementation-defined conversion on
64-bit systems.

Such entries exist in the wild, since old useradd versions used to
create them, so they are still accepted by the parser; they are only
ignored during allocation.

Co-authored-by: Dan Anderson <https://github.com/MillaFleurs>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Hadi Chokr <hadichokr@icloud.com>
lib/subordinateio.c

index af3b2807cd13f8b177d26b5e63dc51020b5221a5..97994168a3d7fd623f5d37c463634c58610bfcbd 100644 (file)
@@ -360,6 +360,9 @@ find_free_range(struct commonio_db *db, id_t min, id_t max, unsigned long count)
        while (NULL != (range = commonio_next(db))) {
                intmax_t  first, last;
 
+               if (range->count == 0)
+                       continue;
+
                first = range->start;
                last = first - 1LL + range->count;