]> source.dussan.org Git - rspamd.git/commitdiff
Fix coredumps on some specific messages with specific urls.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 19 Jul 2011 13:01:17 +0000 (17:01 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 19 Jul 2011 13:01:17 +0000 (17:01 +0400)
Fix coredumps while closing log file.
Fix parsing of chunked HTTP replies.

src/logger.c
src/map.c
src/url.c

index db4143ff3663b5bcaa4e39fdb24ffc2ba19f82b7..0d9f9c9883748ca0d5d2d0385c34e8a27d2c79ff 100644 (file)
@@ -185,7 +185,7 @@ close_log (rspamd_logger_t *rspamd_log)
                                rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %ud times", rspamd_log->repeats);
                                rspamd_log->repeats = 0;
                                if (rspamd_log->saved_message) {
-                                       file_log_function (NULL, rspamd_log->saved_function, rspamd_log->cfg->log_level, rspamd_log->saved_message, TRUE, NULL);
+                                       file_log_function (NULL, rspamd_log->saved_function, rspamd_log->cfg->log_level, rspamd_log->saved_message, TRUE, rspamd_log);
                                        g_free (rspamd_log->saved_message);
                                        g_free (rspamd_log->saved_function);
                                        rspamd_log->saved_message = NULL;
index e5e6d9145a8111d41d7280ebfe34d3267ae7b27a..f85a79031f3b5d8c4d5a740bc86699124396e462 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -236,9 +236,9 @@ read_http_chunked (u_char * buf, size_t len, struct rspamd_map *map, struct http
                /* Read first chunk data */
                skip = read_chunk_header (buf, len, data);
                p += skip;
+               len -= skip;
        }
 
-       len -= skip;
        data->chunk_read += len;
        if (data->chunk_read >= data->chunk) {
                /* Read next chunk and feed callback with remaining buffer */
@@ -247,9 +247,11 @@ read_http_chunked (u_char * buf, size_t len, struct rspamd_map *map, struct http
                        /* copy remaining buffer to start of buffer */
                        data->rlen = len - (remain - p);
                        memmove (p, remain, data->rlen);
+                       data->chunk_read -= data->rlen;
                }
-
-               p = buf + (len - (data->chunk_read - data->chunk));
+       }
+       if (data->chunk_read >= data->chunk) {
+               p = p + (len - (data->chunk_read - data->chunk));
                if (*p != '\r') {
                        if (*p == '0') {
                                return TRUE;
@@ -903,6 +905,11 @@ http_async_callback (gint fd, short what, void *ud)
                        cbd->cbdata.state = 0;
                        cbd->cbdata.prev_data = *cbd->map->user_data;
                        cbd->cbdata.cur_data = NULL;
+                       cbd->data->rlen = 0;
+                       cbd->data->chunk = 0;
+                       cbd->data->chunk_read = 0;
+                       cbd->data->chunked = FALSE;
+                       cbd->data->read_buf[0] = '\0';
 
                        event_add (&cbd->ev, &cbd->tv);
                }
index c8895e1071d13824071ecbe60fe95cfe86fe468b..fd0459ff5c9fe3bcf4c88fc10c14bcf463f92499 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -1252,17 +1252,23 @@ url_try_text (memory_pool_t *pool, const gchar *begin, gsize len, gchar **start,
                                        memcpy (*url_str, m.m_begin, m.m_len);
                                        (*url_str)[m.m_len] = '\0';
                                }
-
+                               if (start != NULL) {
+                                       *start = (gchar *)m.m_begin;
+                               }
+                               if (fin != NULL) {
+                                       *fin = (gchar *)m.m_begin + m.m_len;
+                               }
                        }
                        else {
                                *url_str = NULL;
+                               if (start != NULL) {
+                                       *start = (gchar *)pos;
+                               }
+                               if (fin != NULL) {
+                                       *fin = (gchar *)pos + strlen (m.prefix);
+                               }
                        }
-                       if (start != NULL) {
-                               *start = (gchar *)m.m_begin;
-                       }
-                       if (fin != NULL) {
-                               *fin = (gchar *)m.m_begin + m.m_len;
-                       }
+
                        return TRUE;
                }
        }