]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkid: dynamically allocate devicename array
authorEric Sandeen <sandeen@redhat.com>
Tue, 8 Feb 2011 05:44:26 +0000 (23:44 -0600)
committerKarel Zak <kzak@redhat.com>
Tue, 8 Feb 2011 14:55:59 +0000 (15:55 +0100)
If more than 128 devices are specified on the blkid cmdline,
the devices[] array will overflow.

We can dynamically allocate the devices[] array based on number
of arguments to avoid this problem.

[kzak@redhat.com: - add "if (optind < argc)" check]

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/blkid.c

index 53f2a69e62efcd00bd74792c4f4b07a745da8b86..1fdc17aef4c5846812afffc1d50b6837371f8d1b 100644 (file)
@@ -666,7 +666,7 @@ static void free_types_list(char *list[])
 int main(int argc, char **argv)
 {
        blkid_cache cache = NULL;
-       char *devices[128] = { NULL, };
+       char **devices = NULL;
        char *show[128] = { NULL, };
        char *search_type = NULL, *search_value = NULL;
        char *read = NULL;
@@ -799,6 +799,16 @@ int main(int argc, char **argv)
                        usage(err);
                }
 
+
+       /* The rest of the args are device names */
+       if (optind < argc) {
+               devices = calloc(argc - optind, sizeof(char *));
+               if (!devices) {
+                       fprintf(stderr, "Failed to allocate device name array\n");
+                       goto exit;
+               }
+       }
+
        while (optind < argc)
                devices[numdev++] = argv[optind++];
 
@@ -941,5 +951,6 @@ exit:
        free_types_list(fltr_type);
        if (!lowprobe && !eval)
                blkid_put_cache(cache);
+       free(devices);
        return err;
 }