From: Luca Boccassi Date: Sat, 11 Apr 2026 21:04:37 +0000 (+0100) Subject: uid-range: add assert to prevent underflow in coalesce loop X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff102359b7cf767c9c793a163ff34d95370d0107;p=thirdparty%2Fsystemd.git uid-range: add assert to prevent underflow in coalesce loop Coverity flags range->n_entries - j as a potential underflow in the memmove size calculation. Add assert(range->n_entries > 0) before decrementing n_entries, which holds since the loop condition guarantees j < n_entries. CID#1548015 Follow-up for 8dcc66cefc8ab489568c737adcba960756d76a3c --- diff --git a/src/basic/uid-range.c b/src/basic/uid-range.c index 3d8f8445c45..62c7d7d928e 100644 --- a/src/basic/uid-range.c +++ b/src/basic/uid-range.c @@ -75,6 +75,8 @@ static void uid_range_coalesce(UIDRange *range) { if (range->n_entries > j + 1) memmove(y, y + 1, sizeof(UIDRangeEntry) * (range->n_entries - j - 1)); + /* Silence static analyzers, n_entries > 0 since j < n_entries holds in the loop condition */ + assert(range->n_entries > 0); range->n_entries--; /* Silence static analyzers, j cannot be 0 here since it starts at i + 1, i.e. >= 1 */