]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: add assert for offset + current_size overflow safety
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 21:20:39 +0000 (21:20 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 30 Mar 2026 08:37:31 +0000 (09:37 +0100)
Coverity flags a->after->offset + a->after->current_size as a
potential overflow. Both values are validated as not UINT64_MAX
by existing asserts, add an explicit overflow check to document
the invariant for static analyzers.

CID#1548063

Follow-up for e594a3b154bd06c535a934a1cc7231b1ef76df73

src/repart/repart.c

index d672db6d266b4b55df94c4e3a74814ce61d7ea7b..7a8bc00919e85e34837c2d2197dfd3d4ee7b3b12 100644 (file)
@@ -1247,6 +1247,8 @@ static uint64_t free_area_current_end(Context *context, const FreeArea *a) {
 
         assert(a->after->offset != UINT64_MAX);
         assert(a->after->current_size != UINT64_MAX);
+        /* Silence static analyzers */
+        assert(a->after->current_size <= UINT64_MAX - a->after->offset);
 
         /* Calculate where the free area ends, based on the offset of the partition preceding it. */
         return round_up_size(a->after->offset + a->after->current_size, context->grain_size) + free_area_available(a);