]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: verify partno from template
authorKarel Zak <kzak@redhat.com>
Fri, 17 Feb 2017 12:15:09 +0000 (13:15 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 17 Feb 2017 12:17:48 +0000 (13:17 +0100)
* verify partno from template when create a new partition
* remove unnecessary l->ext_offset check

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c
libfdisk/src/partition.c

index c7c7772e8ff9963ec8d62e3c5151c65320c0f0e7..0c2006ed6f593a9e1f1d2ce3aa79801c8c9fd2d7 100644 (file)
@@ -1548,7 +1548,7 @@ static int dos_add_partition(struct fdisk_context *cxt,
                }
 
        /* pa specifies start, but outside extended partition */
-       } else if (pa && fdisk_partition_has_start(pa) && l->ext_offset) {
+       } else if (pa && fdisk_partition_has_start(pa)) {
                DBG(LABEL, ul_debug("DOS: pa template %p: add primary", pa));
                rc = get_partition_unused_primary(cxt, pa, &res);
                if (rc == 0) {
index f507f20e36c8c7ed17689a7b5cb83daad7db3f2e..1e8c1eb32862114ff92fa1f5624986542bf438d6 100644 (file)
@@ -733,7 +733,8 @@ int fdisk_partition_next_partno(
 
                DBG(PART, ul_debugobj(pa, "next partno (specified=%zu)", pa->partno));
 
-               if (pa->partno >= cxt->label->nparts_max)
+               if (pa->partno >= cxt->label->nparts_max ||
+                   fdisk_is_partition_used(cxt, pa->partno))
                        return -ERANGE;
                *n = pa->partno;
        } else