]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: make table-length usage more robust
authorKarel Zak <kzak@redhat.com>
Wed, 18 May 2016 12:15:02 +0000 (14:15 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 18 May 2016 12:15:02 +0000 (14:15 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c
libfdisk/src/script.c

index ff435e3ea2c45a4c6e9bbf610dae08f23b252c4d..eaa9f4803b9874f576320b4d0c2b3fbc1278e90a 100644 (file)
@@ -2503,6 +2503,8 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, unsigned long new)
        gpt = self_label(cxt);
 
        old = le32_to_cpu(gpt->pheader->npartition_entries);
+       if (old == new)
+               return 0;       /* do nothing, say nothing */
 
        /* calculate the size (bytes) of the entries array */
        new_size = new * le32_to_cpu(gpt->pheader->sizeof_partition_entry);
index fd05bf703d3ed2b39232aaa767b84fa40bcf348c..75e1b52debd4311e658eba6b0c7db247f78dba37 100644 (file)
@@ -1346,10 +1346,15 @@ int fdisk_apply_script_headers(struct fdisk_context *cxt, struct fdisk_script *d
                return rc;
 
        str = fdisk_script_get_header(dp, "table-length");
-       if (str)
-               return fdisk_gpt_set_npartitions(cxt, strtoul(str, NULL, 0));
+       if (str) {
+               uintmax_t sz;
 
-       return 0;
+               rc = parse_size(str, &sz, NULL);
+               if (rc == 0)
+                       rc = fdisk_gpt_set_npartitions(cxt, sz);
+       }
+
+       return rc;
 }
 
 /**