Here's a patch that should fix the problem.  The package builds and
passes its test suite with this patch applied.  However I don't know how
to use the server and I don't have appropriate test data for this bug,
so the fix still needs to be verified.

Ben.

--- imap4d/fetch.c~     2006-03-12 14:25:50.000000000 +0000
+++ imap4d/fetch.c      2006-12-02 14:34:24.000000000 +0000
@@ -1160,12 +1160,11 @@
       offset = 0;
       if (max)
        {
-         util_send (" {%u}\r\n", max);
+         util_send (" {%lu}\r\n", max);
          while (mu_stream_read (rfc, buffer, sizeof (buffer) - 1, offset,
                              &n) == 0 && n > 0)
            {
-             buffer[n] = '\0';
-             util_send ("%s", buffer);
+             util_send_raw (buffer, n);
              offset += n;
            }
        }
@@ -1190,13 +1189,11 @@
          end -= n;
          buffer += n;
        }
-      /* Make sure we null terminate.  */
-      *buffer = '\0';
       util_send ("<%lu>", start);
       if (total)
        {
          util_send (" {%s}\r\n", mu_umaxtostr (0, total));
-         util_send ("%s", p);
+         util_send_raw (p, total);
        }
       else
        util_send (" \"\"");
--- imap4d/imap4d.h~    2006-04-07 15:08:54.000000000 +0100
+++ imap4d/imap4d.h     2006-12-02 14:27:16.000000000 +0000
@@ -242,6 +242,7 @@
   
 /* Helper functions.  */
 extern int  util_out (int, const char *, ...);
+extern int  util_send_raw (const char *, size_t);
 extern int  util_send (const char *, ...);
 extern int  util_send_qstring (const char *);
 extern int  util_send_literal (const char *);
--- imap4d/util.c~      2006-04-07 15:08:55.000000000 +0100
+++ imap4d/util.c       2006-12-02 14:25:55.000000000 +0000
@@ -348,6 +348,15 @@
 }
 
 int
+util_send_raw (const char *data, size_t len)
+{
+  if (daemon_param.transcript)
+    syslog (LOG_DEBUG, "sent: %s", data);
+
+  return mu_stream_sequential_write (ostream, data, len);
+}
+
+int
 util_send (const char *format, ...)
 {
   char *buf = NULL;
@@ -360,10 +369,7 @@
   if (!buf)
       imap4d_bye (ERR_NO_MEM);
 
-  if (daemon_param.transcript)
-    syslog (LOG_DEBUG, "sent: %s", buf);
-
-  status = mu_stream_sequential_write (ostream, buf, strlen (buf));
+  status = util_send_raw (buf, strlen(buf));
   free (buf);
 
   return status;
-- END --

-- 
Ben Hutchings
It is easier to write an incorrect program than to understand a correct one.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to