summaryrefslogtreecommitdiffstats
path: root/misc-utils/blkid.c
diff options
context:
space:
mode:
authorEric Sandeen2011-02-08 06:44:26 +0100
committerKarel Zak2011-02-08 15:55:59 +0100
commitea51c09c11f7110eca54fa35ab5ac51a7635c8c2 (patch)
treeadd830056d9af1d2b0c56dc3324c04ebbe6f40d7 /misc-utils/blkid.c
parentwipefs: use write_all from include/writeall.h (diff)
downloadkernel-qcow2-util-linux-ea51c09c11f7110eca54fa35ab5ac51a7635c8c2.tar.gz
kernel-qcow2-util-linux-ea51c09c11f7110eca54fa35ab5ac51a7635c8c2.tar.xz
kernel-qcow2-util-linux-ea51c09c11f7110eca54fa35ab5ac51a7635c8c2.zip
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 <sandeen@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/blkid.c')
-rw-r--r--misc-utils/blkid.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 53f2a69e6..1fdc17aef 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;
}