From: Eric Sandeen Date: Tue, 8 Feb 2011 05:44:26 +0000 (-0600) Subject: blkid: dynamically allocate devicename array X-Git-Tag: v2.19~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea51c09c11f7110eca54fa35ab5ac51a7635c8c2;p=thirdparty%2Futil-linux.git blkid: dynamically allocate devicename array 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 Signed-off-by: Karel Zak --- diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 53f2a69e62..1fdc17aef4 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -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; }