summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-08-28 17:22:40 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-08-28 17:22:40 +0300
commitdc579c0356464e7e9ce9d25ab60475703bde52d4 (patch)
treea249b0eeba4186240f39ca69ea52d40758af38ef
parent19f93a88c9a2cd1bbe66472514db16c13a333984 (diff)
downloadmailutils-dc579c0356464e7e9ce9d25ab60475703bde52d4.tar.gz
mailutils-dc579c0356464e7e9ce9d25ab60475703bde52d4.tar.bz2
Bugfixes
* include/mailutils/header.h (mu_header_invalidate): New proto. * mailbox/header.c (mu_header_invalidate): New function. * libmu_argp/muinit.c (get_canonical_name): Avoid coredumping if argp_program_version is NULL. * mailbox/base64.c (mu_base64_decode): Fix inconsistent return code. * mailbox/debug.c (mu_debug_destroy): Allow for debug->stream == NULL. * mailbox/mapfile_stream.c (_mapfile_truncate): Incorrect size was used when unmapping. * mailbox/message.c (mu_message_create_copy): Use a temporary memory stream. (mu_message_get_body): Comment out the check for MESSAGE_INTERNAL_STREAM. (_message_get_stream): Initialize message header and body. * mailbox/progmailer.c (mu_progmailer_send): Check return from the mu_header_get_streamref. * mailbox/stream.c (_stream_scandelim, _stream_readdelim): If size is 0, return MU_ERR_BUFSPACE.
-rw-r--r--include/mailutils/header.h1
-rw-r--r--lib/allocsa.valgrind7
-rw-r--r--libmu_argp/muinit.c6
-rw-r--r--mailbox/base64.c2
-rw-r--r--mailbox/debug.c15
-rw-r--r--mailbox/header.c9
-rw-r--r--mailbox/mapfile_stream.c2
-rw-r--r--mailbox/message.c56
-rw-r--r--mailbox/progmailer.c17
-rw-r--r--mailbox/stream.c4
10 files changed, 80 insertions, 39 deletions
diff --git a/include/mailutils/header.h b/include/mailutils/header.h
index d16211254..57a1107ae 100644
--- a/include/mailutils/header.h
+++ b/include/mailutils/header.h
@@ -78,6 +78,7 @@ extern "C" {
extern int mu_header_create (mu_header_t *, const char *, size_t);
extern void mu_header_destroy (mu_header_t *);
+extern int mu_header_invalidate (mu_header_t);
extern int mu_header_is_modified (mu_header_t);
extern int mu_header_clear_modified (mu_header_t);
diff --git a/lib/allocsa.valgrind b/lib/allocsa.valgrind
deleted file mode 100644
index f4c77d686..000000000
--- a/lib/allocsa.valgrind
+++ /dev/null
@@ -1,7 +0,0 @@
-# Suppress a valgrind message about use of uninitialized memory in freesa().
-# This use is OK because it provides only a speedup.
-{
- freesa
- Memcheck:Cond
- fun:freesa
-}
diff --git a/libmu_argp/muinit.c b/libmu_argp/muinit.c
index 805fc30ca..9433fddea 100644
--- a/libmu_argp/muinit.c
+++ b/libmu_argp/muinit.c
@@ -75,8 +75,10 @@ get_canonical_name ()
{
char *name;
size_t len;
- char *p = strchr (argp_program_version, ' ');
- if (!p)
+ char *p;
+
+ if (!argp_program_version ||
+ !(p = strchr (argp_program_version, ' ')))
return strdup (mu_program_name);
len = p - argp_program_version;
name = malloc (len + 1);
diff --git a/mailbox/base64.c b/mailbox/base64.c
index fd0131e02..f70a40baa 100644
--- a/mailbox/base64.c
+++ b/mailbox/base64.c
@@ -88,7 +88,7 @@ mu_base64_decode (const unsigned char *input, size_t input_len,
|| input[2] > 127 || ((input[2] != '=') && (b64val[input[2]] == -1))
|| input[3] > 127 || ((input[3] != '=')
&& (b64val[input[3]] == -1)))
- return -1;
+ return EINVAL;
*out++ = (b64val[input[0]] << 2) | (b64val[input[1]] >> 4);
if (input[2] != '=')
{
diff --git a/mailbox/debug.c b/mailbox/debug.c
index 4c3167448..93fab7c59 100644
--- a/mailbox/debug.c
+++ b/mailbox/debug.c
@@ -55,13 +55,16 @@ mu_debug_destroy (mu_debug_t *pdebug, void *owner)
mu_debug_t debug = *pdebug;
if (debug->owner == owner)
{
- mu_off_t len = 0;
- int rc = mu_stream_size (debug->stream, &len);
- if (rc == 0 && len)
- /* Flush leftover data */
- mu_debug_printf (debug, 0, "\n");
+ if (debug->stream)
+ {
+ mu_off_t len = 0;
+ int rc = mu_stream_size (debug->stream, &len);
+ if (rc == 0 && len)
+ /* Flush leftover data */
+ mu_debug_printf (debug, 0, "\n");
- mu_stream_destroy (&debug->stream);
+ mu_stream_destroy (&debug->stream);
+ }
if (debug->destroy)
debug->destroy (debug->data);
free (*pdebug);
diff --git a/mailbox/header.c b/mailbox/header.c
index 669093c2e..f49ea8621 100644
--- a/mailbox/header.c
+++ b/mailbox/header.c
@@ -911,6 +911,15 @@ mu_header_size (mu_header_t header, size_t *psize)
return status;
}
+int
+mu_header_invalidate (mu_header_t hdr)
+{
+ if (hdr == NULL)
+ return EINVAL;
+ mu_hdrent_free_list (hdr);
+ return 0;
+}
+
static void
mu_hdrent_fixup (mu_header_t hdr, struct mu_hdrent *ent)
diff --git a/mailbox/mapfile_stream.c b/mailbox/mapfile_stream.c
index 0b6014708..89b3e4776 100644
--- a/mailbox/mapfile_stream.c
+++ b/mailbox/mapfile_stream.c
@@ -129,7 +129,7 @@ _mapfile_truncate (mu_stream_t stream, mu_off_t len)
if (mfs->ptr == MAP_FAILED)
return EINVAL;
/* Remap. */
- if (mfs->ptr && munmap (mfs->ptr, len) != 0)
+ if (mfs->ptr && munmap (mfs->ptr, mfs->size) != 0)
{
int err = errno;
mfs->ptr = MAP_FAILED;
diff --git a/mailbox/message.c b/mailbox/message.c
index a792ebb6b..9e371332d 100644
--- a/mailbox/message.c
+++ b/mailbox/message.c
@@ -558,33 +558,36 @@ mu_message_create_copy (mu_message_t *to, mu_message_t from)
{
int status = 0;
mu_stream_t fromstr = NULL;
- mu_stream_t tostr = NULL;
- size_t n = 0;
- char buf[512];
+ mu_stream_t tmp = NULL;
if (!to)
return MU_ERR_OUT_PTR_NULL;
if (!from)
return EINVAL;
- if ((status = mu_message_create (to, NULL)))
+ status = mu_memory_stream_create (&tmp, MU_STREAM_RDWR|MU_STREAM_SEEK);
+ if (status)
return status;
- mu_message_get_streamref (from, &fromstr);
- mu_message_get_streamref (*to, &tostr);
+ status = mu_message_get_streamref (from, &fromstr);
+ if (status)
+ {
+ mu_stream_destroy (&tmp);
+ return status;
+ }
- status = mu_stream_seek (fromstr, 0, MU_SEEK_SET, NULL);
+ status = mu_stream_copy (tmp, fromstr, 0);
if (status == 0)
- while ((status = mu_stream_readline (fromstr, buf, sizeof (buf), &n)) == 0
- && n > 0)
- mu_stream_write (tostr, buf, n, NULL);
+ {
+ status = mu_message_create (to, NULL);
+ if (status == 0)
+ mu_message_set_stream (*to, tmp, NULL);
+ }
- mu_stream_destroy (&fromstr);
- mu_stream_destroy (&tostr);
-
if (status)
- mu_message_destroy (to, NULL);
-
+ mu_stream_destroy (&tmp);
+ mu_stream_destroy (&fromstr);
+
return status;
}
@@ -710,14 +713,16 @@ mu_message_get_body (mu_message_t msg, mu_body_t *pbody)
int status = mu_body_create (&body, msg);
if (status != 0)
return status;
- /* If a stream is already set use it to create the body stream. */
+ /* If a stream is already set, use it to create the body stream. */
/* FIXME: I'm not sure if the second condition is really needed */
- if (msg->stream && (msg->flags & MESSAGE_INTERNAL_STREAM))
+ if (msg->stream/* && (msg->flags & MESSAGE_INTERNAL_STREAM)*/)
{
size_t size = 0;
mu_stream_t stream;
int flags = 0;
-
+
+ /* FIXME: The size cannot be used as offset, because
+ the headers might have been modified in between. */
status = mu_header_size (msg->header, &size);
if (status)
return status;
@@ -779,7 +784,20 @@ _message_get_stream (mu_message_t msg, mu_stream_t *pstream, int ref)
if (msg->stream == NULL)
{
- int status = _message_stream_create (&msg->stream, msg, MU_STREAM_RDWR);
+ int status;
+ mu_header_t hdr;
+ mu_body_t body;
+
+ /* FIXME: Kind of a kludge: make sure the message has header
+ and body initialized. */
+ status = mu_message_get_header (msg, &hdr);
+ if (status)
+ return status;
+ status = mu_message_get_body (msg, &body);
+ if (status)
+ return status;
+
+ status = _message_stream_create (&msg->stream, msg, MU_STREAM_RDWR);
if (status)
return status;
msg->flags |= MESSAGE_INTERNAL_STREAM;
diff --git a/mailbox/progmailer.c b/mailbox/progmailer.c
index 75f0f59fb..f39440fcd 100644
--- a/mailbox/progmailer.c
+++ b/mailbox/progmailer.c
@@ -188,8 +188,13 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
if (!pm || !msg)
return EINVAL;
mu_message_get_header (msg, &hdr);
- mu_header_get_streamref (hdr, &stream);
-
+ status = mu_header_get_streamref (hdr, &stream);
+ if (status)
+ {
+ MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+ "cannot get header stream: %s\n", mu_strerror (status));
+ return status;
+ }
MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending headers...\n");
mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
while ((status = mu_stream_readline (stream, buffer, sizeof (buffer),
@@ -225,7 +230,13 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending body...\n");
mu_message_get_body (msg, &body);
- mu_body_get_streamref (body, &stream);
+ status = mu_body_get_streamref (body, &stream);
+ if (status)
+ {
+ MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+ "cannot get body stream: %s\n", mu_strerror (status));
+ return status;
+ }
mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
while ((status = mu_stream_read (stream, buffer, sizeof (buffer),
diff --git a/mailbox/stream.c b/mailbox/stream.c
index b06442137..95524ec6b 100644
--- a/mailbox/stream.c
+++ b/mailbox/stream.c
@@ -610,6 +610,8 @@ _stream_scandelim (mu_stream_t stream, char *buf, size_t size, int delim,
size_t nread = 0;
size--;
+ if (size == 0)
+ return MU_ERR_BUFSPACE;
while (size)
{
char *p;
@@ -647,6 +649,8 @@ _stream_readdelim (mu_stream_t stream, char *buf, size_t size,
size_t n = 0, rdn;
size--;
+ if (size == 0)
+ return MU_ERR_BUFSPACE;
for (n = 0;
n < size && (rc = mu_stream_read (stream, &c, 1, &rdn)) == 0 && rdn;)
{

Return to:

Send suggestions and report system problems to the System administrator.