From: Hadi Chokr Date: Thu, 9 Jul 2026 13:28:41 +0000 (+0000) Subject: subids: find_free_range(): skip empty ranges X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=36072d80dbae2137f6190caf6906e7cb911102c7;p=thirdparty%2Fshadow.git subids: find_free_range(): skip empty ranges 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 Reviewed-by: Alejandro Colomar Signed-off-by: Hadi Chokr --- diff --git a/lib/subordinateio.c b/lib/subordinateio.c index af3b2807c..97994168a 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -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;