From 7098e911c4a731a9062b75c6a477cd203042860d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 13 Sep 2023 00:08:39 +0200 Subject: [PATCH] libfdisk: (dos) remove usage of VLA MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Variable-length-arrays are susceptible to security issues, avoid them. Signed-off-by: Thomas Weißschuh --- libfdisk/src/dos.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 1d17943b89..33dbca8c31 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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; } -- 2.47.3