From: Luca Boccassi Date: Sat, 28 Mar 2026 21:52:57 +0000 (+0000) Subject: repart: use INC_SAFE for partition min size accumulation X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1eb2bd5aaf14650a3433767fc44ffaef85407b21;p=thirdparty%2Fsystemd.git repart: use INC_SAFE for partition min size accumulation Use overflow-safe INC_SAFE() instead of raw addition when accumulating partition minimum size components. CID#1548041 Follow-up for 170c98234530af6af487d37057b6e687569f8f91 --- diff --git a/src/repart/repart.c b/src/repart/repart.c index 7a8bc00919e..1cdc0a051f6 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -1133,16 +1133,16 @@ static uint64_t partition_min_size(const Context *context, const Partition *p) { uint64_t d = 0; if (p->encrypt != ENCRYPT_OFF) - d += round_up_size(LUKS2_METADATA_KEEP_FREE, context->grain_size); + assert_se(INC_SAFE(&d, round_up_size(LUKS2_METADATA_KEEP_FREE, context->grain_size))); if (p->copy_blocks_size != UINT64_MAX) - d += round_up_size(p->copy_blocks_size, context->grain_size); + assert_se(INC_SAFE(&d, round_up_size(p->copy_blocks_size, context->grain_size))); else if (p->format || p->encrypt != ENCRYPT_OFF) { uint64_t f; /* If we shall synthesize a file system, take minimal fs size into account (assumed to be 4K if not known) */ f = partition_fstype_min_size(context, p); - d += f == UINT64_MAX ? context->grain_size : round_up_size(f, context->grain_size); + assert_se(INC_SAFE(&d, f == UINT64_MAX ? context->grain_size : round_up_size(f, context->grain_size))); } if (d > sz)