[Pkg-libvirt-commits] [libguestfs] 16/266: Warn about large stack frames, and fix a few places with excessive stack usage.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 4d3953f09217e15212d18f53e1cf040d54156f72
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Jul 16 22:05:39 2014 +0100

    Warn about large stack frames, and fix a few places with excessive stack usage.
---
 configure.ac   |  6 ++++++
 daemon/dd.c    |  2 +-
 daemon/proto.c | 45 +++++++++++++++++++++++++++++++++++----------
 daemon/zero.c  |  4 ++--
 4 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0d2b132..ec98e4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -181,6 +181,12 @@ gl_WARN_ADD([-Wno-missing-field-initializers])
 dnl Display the name of the warning option with the warning.
 gl_WARN_ADD([-fdiagnostics-show-option])
 
+dnl Now some warnings we want to enable and/or customize ...
+
+dnl Warn about large stack allocations.  10000 happens to be the
+dnl same size as Coverity warns about.
+gl_WARN_ADD([-Wframe-larger-than=10000])
+
 AC_SUBST([WARN_CFLAGS])
 
 AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
diff --git a/daemon/dd.c b/daemon/dd.c
index cd4e849..d29c527 100644
--- a/daemon/dd.c
+++ b/daemon/dd.c
@@ -108,7 +108,7 @@ do_copy_size (const char *src, const char *dest, int64_t ssize)
   uint64_t position = 0, size = (uint64_t) ssize;
 
   while (position < size) {
-    char buf[1024*1024];
+    char buf[BUFSIZ];
 
     /* Calculate bytes to copy. */
     uint64_t n64 = size - position;
diff --git a/daemon/proto.c b/daemon/proto.c
index d23c6a4..d387352 100644
--- a/daemon/proto.c
+++ b/daemon/proto.c
@@ -222,28 +222,43 @@ static void send_error (int errnum, const char *msg);
 void
 reply_with_error_errno (int err, const char *fs, ...)
 {
-  char buf[GUESTFS_ERROR_LEN];
+  CLEANUP_FREE char *buf = NULL;
   va_list args;
+  int r;
 
   va_start (args, fs);
-  vsnprintf (buf, sizeof buf, fs, args);
+  r = vasprintf (&buf, fs, args);
   va_end (args);
 
+  if (r == -1) {
+    perror ("vasprintf");
+    exit (EXIT_FAILURE);
+  }
+
   send_error (err, buf);
 }
 
 void
 reply_with_perror_errno (int err, const char *fs, ...)
 {
-  char buf1[GUESTFS_ERROR_LEN];
-  char buf2[GUESTFS_ERROR_LEN];
+  CLEANUP_FREE char *buf1 = NULL;
+  CLEANUP_FREE char *buf2 = NULL;
   va_list args;
+  int r;
 
   va_start (args, fs);
-  vsnprintf (buf1, sizeof buf1, fs, args);
+  r = vasprintf (&buf1, fs, args);
   va_end (args);
 
-  snprintf (buf2, sizeof buf2, "%s: %s", buf1, strerror (err));
+  if (r == -1) {
+  error:
+    perror ("vasprintf");
+    exit (EXIT_FAILURE);
+  }
+
+  r = asprintf (&buf2, "%s: %s", buf1, strerror (err));
+  if (r == -1)
+    goto error;
 
   send_error (err, buf2);
 }
@@ -252,7 +267,7 @@ static void
 send_error (int errnum, const char *msg)
 {
   XDR xdr;
-  char buf[GUESTFS_ERROR_LEN + 200];
+  CLEANUP_FREE char *buf = NULL;
   char lenbuf[4];
   struct guestfs_message_header hdr;
   struct guestfs_message_error err;
@@ -260,7 +275,12 @@ send_error (int errnum, const char *msg)
 
   fprintf (stderr, "guestfsd: error: %s\n", msg);
 
-  xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
+  buf = malloc (GUESTFS_ERROR_LEN + 200);
+  if (!buf) {
+    perror ("malloc");
+    exit (EXIT_FAILURE);
+  }
+  xdrmem_create (&xdr, buf, GUESTFS_ERROR_LEN + 200, XDR_ENCODE);
 
   memset (&hdr, 0, sizeof hdr);
   hdr.prog = GUESTFS_PROGRAM;
@@ -308,12 +328,17 @@ void
 reply (xdrproc_t xdrp, char *ret)
 {
   XDR xdr;
-  char buf[GUESTFS_MESSAGE_MAX];
+  CLEANUP_FREE char *buf = NULL;
   char lenbuf[4];
   struct guestfs_message_header hdr;
   uint32_t len;
 
-  xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
+  buf = malloc (GUESTFS_MESSAGE_MAX);
+  if (!buf) {
+    perror ("malloc");
+    exit (EXIT_FAILURE);
+  }
+  xdrmem_create (&xdr, buf, GUESTFS_MESSAGE_MAX, XDR_ENCODE);
 
   memset (&hdr, 0, sizeof hdr);
   hdr.prog = GUESTFS_PROGRAM;
diff --git a/daemon/zero.c b/daemon/zero.c
index ff0ea97..ae8e84d 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -197,7 +197,7 @@ int
 do_is_zero (const char *path)
 {
   int fd;
-  char buf[1024*1024];
+  char buf[BUFSIZ];
   ssize_t r;
 
   CHROOT_IN;
@@ -234,7 +234,7 @@ int
 do_is_zero_device (const char *device)
 {
   int fd;
-  char buf[1024*1024];
+  char buf[BUFSIZ];
   ssize_t r;
 
   fd = open (device, O_RDONLY|O_CLOEXEC);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list