From c949fa98d8737cd0a14ea071d141d2c6a0b35faa Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 17 Sep 2015 11:44:08 +0200 Subject: libfdisk: (gpt) control ranges in set_partition Signed-off-by: Karel Zak --- libfdisk/src/gpt.c | 15 ++++++++++++--- libfdisk/src/partition.c | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'libfdisk') diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 98da5aac9..81741679a 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -1751,11 +1751,20 @@ static int gpt_set_partition(struct fdisk_context *cxt, size_t n, end = xstart + xsize - 1ULL; } - if (!FDISK_IS_UNDEF(start)) + if (!FDISK_IS_UNDEF(start)) { + if (start < le64_to_cpu(gpt->pheader->first_usable_lba)) { + fdisk_warnx(cxt, _("The begin of the partition overflows FirstUsableLBA.")); + return -EINVAL; + } e->lba_start = cpu_to_le64(start); - if (!FDISK_IS_UNDEF(end)) + } + if (!FDISK_IS_UNDEF(end)) { + if (end > le64_to_cpu(gpt->pheader->last_usable_lba)) { + fdisk_warnx(cxt, _("The end of the partition overflows LastUsableLBA.")); + return -EINVAL; + } e->lba_end = cpu_to_le64(end); - + } gpt_recompute_crc(gpt->pheader, gpt->ents); gpt_recompute_crc(gpt->bheader, gpt->ents); diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 83d077414..aeba7c402 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -1146,6 +1146,7 @@ int fdisk_set_partition(struct fdisk_context *cxt, size_t partno, rc = cxt->label->op->set_part(cxt, partno, xpa); done: + DBG(CXT, ul_debugobj(cxt, "set_partition() rc=%d", rc)); if (xpa != pa) fdisk_unref_partition(xpa); return rc; -- cgit v1.2.3-55-g7522