]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) control ranges in set_partition
authorKarel Zak <kzak@redhat.com>
Thu, 17 Sep 2015 09:44:08 +0000 (11:44 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 17 Sep 2015 09:44:08 +0000 (11:44 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c
libfdisk/src/partition.c

index 98da5aac9a7b04a11484ec367b940d4a064dae5c..81741679ace4cde90467a609c5afde4aebec75d5 100644 (file)
@@ -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);
 
index 83d077414042e933141500855da1cbb2ddf2dc79..aeba7c402f86b32e9094e1ffe47aa165058638a9 100644 (file)
@@ -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;