]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: remove usage of VLA
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Sep 2023 22:09:39 +0000 (00:09 +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>
disk-utils/fdisk-list.c

index 21d215e5844a85c3ea6f61bf6348c953ad9cec9f..a1b6a844d4af2b60e244a80ac1d351e7e207a167 100644 (file)
@@ -469,21 +469,24 @@ void list_available_columns(FILE *out)
 static int fieldname_to_id(const char *name, size_t namesz)
 {
        const struct fdisk_field *fl;
-       char buf[namesz + 1];
+       char *buf;
 
        assert(name);
        assert(namesz);
        assert(fields_label);
 
-       memcpy(buf, name, namesz);
-       buf[namesz] = '\0';
+       buf = strndup(name, namesz);
+       if (!buf)
+               return -1;
 
        fl = fdisk_label_get_field_by_name(fields_label, buf);
        if (!fl) {
                warnx(_("%s unknown column: %s"),
                                fdisk_label_get_name(fields_label), buf);
+               free(buf);
                return -1;
        }
+       free(buf);
        return fdisk_field_get_id(fl);
 }