]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) remove usage of VLA
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Sep 2023 22:08:39 +0000 (00:08 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Wed, 13 Sep 2023 06:37:02 +0000 (08:37 +0200)
Variable-length-arrays are susceptible to security issues, avoid them.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libfdisk/src/dos.c

index 1d17943b89a567902a86bee7623f55c975dd2a30..33dbca8c311426f28bf779297810bfdfd015e1c5 100644 (file)
@@ -1727,14 +1727,22 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
 {
        size_t i, j;
        fdisk_sector_t total = 1, n_sectors = cxt->total_sectors;
-       fdisk_sector_t first[cxt->label->nparts_max],
-                      last[cxt->label->nparts_max];
+       fdisk_sector_t *first, *last;
        struct dos_partition *p;
        struct fdisk_dos_label *l = self_label(cxt);
        int nerrors = 0;
 
        assert(fdisk_is_label(cxt, DOS));
 
+       first = calloc(cxt->label->nparts_max, sizeof(*first));
+       last = calloc(cxt->label->nparts_max, sizeof(*first));
+
+       if (!first || !last) {
+               free(first);
+               free(last);
+               return -ENOMEM;
+       }
+
        fill_bounds(cxt, first, last);
        for (i = 0; i < cxt->label->nparts_max; i++) {
                struct pte *pe = self_pte(cxt, i);
@@ -1818,6 +1826,8 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
                        P_("%d error detected.", "%d errors detected.", nerrors),
                        nerrors);
 
+       free(first);
+       free(last);
        return nerrors;
 }