diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-09-15 13:01:10 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-09-15 13:01:10 +0100 |
commit | 2383d7a78e8abc308e36b2045087a9785c893f49 (patch) | |
tree | 919b434bcb07c99f6c815e6e03b1394a78858ff4 /cat | |
parent | a67129b0fb45b2f83eb711c6c599569d0f53e580 (diff) | |
download | libguestfs-2383d7a78e8abc308e36b2045087a9785c893f49.tar.gz libguestfs-2383d7a78e8abc308e36b2045087a9785c893f49.tar.xz libguestfs-2383d7a78e8abc308e36b2045087a9785c893f49.zip |
syntax: Remove PATH_MAX-sized buffers allocated on the stack.
On Linux PATH_MAX is 4096, but on some platforms it can be much larger
or even not defined (ie. unlimited). Therefore using a PATH_MAX-sized
stack buffer is not a great idea for portable programs.
This change removes use of PATH_MAX-sized stack-allocated buffers.
This change only applies to the library and standalone programs.
Inside the daemon, memory allocation is much more complicated so I
have not changed those (yet).
Found by 'make syntax-check'.
Diffstat (limited to 'cat')
-rw-r--r-- | cat/virt-filesystems.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/cat/virt-filesystems.c b/cat/virt-filesystems.c index 690fe3c6..c28c4b1c 100644 --- a/cat/virt-filesystems.c +++ b/cat/virt-filesystems.c @@ -582,12 +582,14 @@ do_output_vgs (void) exit (EXIT_FAILURE); for (i = 0; i < vgs->len; ++i) { - char name[PATH_MAX]; + char *name; char uuid[33]; char **parents; - strcpy (name, "/dev/"); - strcpy (&name[5], vgs->val[i].vg_name); + if (asprintf (&name, "/dev/%s", vgs->val[i].vg_name) == -1) { + perror ("asprintf"); + exit (EXIT_FAILURE); + } memcpy (uuid, vgs->val[i].vg_uuid, 32); uuid[32] = '\0'; @@ -597,6 +599,7 @@ do_output_vgs (void) write_row (name, "vg", NULL, NULL, -1, (int64_t) vgs->val[i].vg_size, parents, uuid); + free (name); free_strings (parents); } |