[Pkg-libvirt-commits] [libguestfs] 17/266: daemon: Truncate long error messages so XDR encoding doesn't fail.

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 4106c97934ec5461ae854939185bfa574374bca2
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Jul 17 09:57:42 2014 +0100

    daemon: Truncate long error messages so XDR encoding doesn't fail.
---
 daemon/proto.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/daemon/proto.c b/daemon/proto.c
index d387352..c9de36d 100644
--- a/daemon/proto.c
+++ b/daemon/proto.c
@@ -217,7 +217,7 @@ main_loop (int _sock)
   }
 }
 
-static void send_error (int errnum, const char *msg);
+static void send_error (int errnum, char *msg);
 
 void
 reply_with_error_errno (int err, const char *fs, ...)
@@ -264,7 +264,7 @@ reply_with_perror_errno (int err, const char *fs, ...)
 }
 
 static void
-send_error (int errnum, const char *msg)
+send_error (int errnum, char *msg)
 {
   XDR xdr;
   CLEANUP_FREE char *buf = NULL;
@@ -273,8 +273,18 @@ send_error (int errnum, const char *msg)
   struct guestfs_message_error err;
   unsigned len;
 
+  /* Print the full length error message. */
   fprintf (stderr, "guestfsd: error: %s\n", msg);
 
+  /* We want to truncate the error message to GUESTFS_ERROR_LEN bytes
+   * (not including the \0 since it is not encoded in XDR).  This is
+   * so that the xdr_guestfs_message_error call below won't fail on
+   * very long error messages.  We can overwrite the message since all
+   * callers of send_error pass a temporary buffer.
+   */
+  if (strlen (msg) > GUESTFS_ERROR_LEN)
+    msg[GUESTFS_ERROR_LEN] = '\0';
+
   buf = malloc (GUESTFS_ERROR_LEN + 200);
   if (!buf) {
     perror ("malloc");

-- 
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