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>
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;
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++];
free_types_list(fltr_type);
if (!lowprobe && !eval)
blkid_put_cache(cache);
+ free(devices);
return err;
}