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 /test-tool/test-tool.c | |
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 'test-tool/test-tool.c')
-rw-r--r-- | test-tool/test-tool.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c index ba574ecf..4b764ee4 100644 --- a/test-tool/test-tool.c +++ b/test-tool/test-tool.c @@ -293,7 +293,7 @@ cleanup_wrapper (void) static void set_qemu (const char *path, int use_wrapper) { - char buffer[PATH_MAX]; + char *buffer; struct stat statbuf; int fd; FILE *fp; @@ -318,14 +318,19 @@ set_qemu (const char *path, int use_wrapper) } /* This should be a source directory, so check it. */ - snprintf (buffer, sizeof buffer, "%s/pc-bios", path); + if (asprintf (&buffer, "%s/pc-bios", path) == -1) { + perror ("asprintf"); + exit (EXIT_FAILURE); + } if (stat (buffer, &statbuf) == -1 || !S_ISDIR (statbuf.st_mode)) { fprintf (stderr, _("%s: does not look like a qemu source directory\n"), path); + free (buffer); exit (EXIT_FAILURE); } + free (buffer); /* Make a wrapper script. */ fd = mkstemp (qemuwrapper); |