diff --git a/src/partition/repart.c b/src/partition/repart.c index c7791178b4..fc33a3eb62 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -1922,6 +1922,8 @@ static int determine_current_padding( return log_error_errno(SYNTHETIC_ERRNO(EIO), "Partition has no end!"); offset = fdisk_partition_get_end(p); + assert(offset < UINT64_MAX); + offset++; /* The end is one sector before the next partition or padding. */ assert(offset < UINT64_MAX / secsz); offset *= secsz; @@ -2108,7 +2110,7 @@ static int context_load_partition_table(Context *context) { return log_error_errno(errno, "Failed to stat block device '%s': %m", context->node); if (S_ISREG(st.st_mode) && st.st_size == 0) { - /* User the fallback values if we have no better idea */ + /* Use the fallback values if we have no better idea */ context->sector_size = arg_sector_size ?: 512; context->grain_size = 4096; return /* from_scratch = */ true; diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index 6ddb96d26e..c7510dd3fc 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.sh @@ -1021,6 +1021,88 @@ EOF systemd-dissect -U "$imgs/mnt" } +testcase_free_area_calculation() { + local defs imgs output + + if ! command -v mksquashfs >/dev/null; then + echo "Skipping free area calculation test without squashfs." + return + fi + + defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" + imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" + # shellcheck disable=SC2064 + trap "rm -rf '$defs' '$imgs'" RETURN + chmod a+rx "$defs" + + # https://github.com/systemd/systemd/issues/28225 + echo "*** free area calculation ***" + + tee "$defs/00-ESP.conf" <