aboutsummaryrefslogtreecommitdiffstats
path: root/src/message.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-10 14:20:14 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-10 14:20:14 +0300
commitdb2aa89316d180d8137f4f8f96b5193fd627e894 (patch)
tree81523aa2f68d9a56deb8677c21806f66ba0b8a41 /src/message.c
parent0f3ffee8009da397270ce1ea127dab84285ed432 (diff)
downloadrspamd-db2aa89316d180d8137f4f8f96b5193fd627e894.tar.gz
rspamd-db2aa89316d180d8137f4f8f96b5193fd627e894.zip
* Fix 2 memory issues:
- NULL string when trying to check url regexp - double free of message byte array as mime_stream frees memory in array if it thinks that stream is owner of array's memory
Diffstat (limited to 'src/message.c')
-rw-r--r--src/message.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/message.c b/src/message.c
index 7d30f53f9..c2acaa0cd 100644
--- a/src/message.c
+++ b/src/message.c
@@ -335,12 +335,23 @@ process_message (struct worker_task *task)
tmp->data = task->msg->begin;
tmp->len = task->msg->len;
stream = g_mime_stream_mem_new_with_byte_array (tmp);
+ /*
+ * This causes g_mime_stream not to free memory by itself as it is memory allocated by
+ * pool allocator
+ */
+ g_mime_stream_mem_set_owner (stream, FALSE);
+
msg_debug ("process_message: construct mime parser from string length %ld", (long int)task->msg->len);
/* create a new parser object to parse the stream */
parser = g_mime_parser_new_with_stream (stream);
/* parse the message from the stream */
message = g_mime_parser_construct_message (parser);
+
+ if (message == NULL) {
+ msg_warn ("process_message: cannot construct mime from stream");
+ return -1;
+ }
task->message = message;
memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_object_unref, task->message);
@@ -443,6 +454,11 @@ process_learn (struct controller_session *session)
tmp->data = session->learn_buf->begin;
tmp->len = session->learn_buf->len;
stream = g_mime_stream_mem_new_with_byte_array (tmp);
+ /*
+ * This causes g_mime_stream not to free memory by itself as it is memory allocated by
+ * pool allocator
+ */
+ g_mime_stream_mem_set_owner (stream, FALSE);
/* create a new parser object to parse the stream */
parser = g_mime_parser_new_with_stream (stream);