From: Vsevolod Stakhov Date: Tue, 6 Oct 2015 15:30:52 +0000 (+0100) Subject: Fix other mime library modules. X-Git-Tag: 1.0.5~67^2~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9eb519ef1f48d6d6353276491bdd3423720a0ed5;p=rspamd.git Fix other mime library modules. --- diff --git a/src/libmime/message.c b/src/libmime/message.c index 3537f70c0..183b9bcee 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -112,8 +112,7 @@ parse_recv_header (rspamd_mempool_t * pool, RSPAMD_RECV_STATE_PARSE_IP, RSPAMD_RECV_STATE_SKIP_SPACES, RSPAMD_RECV_STATE_ERROR - } state = RSPAMD_RECV_STATE_INIT, - next_state = RSPAMD_RECV_STATE_INIT; + } state = RSPAMD_RECV_STATE_INIT, next_state = RSPAMD_RECV_STATE_INIT; gboolean is_exim = FALSE; line = rh->decoded; @@ -949,7 +948,7 @@ rspamd_normalize_text_part (struct rspamd_task *task, struct mime_text_part *part) { struct sb_stemmer *stem = NULL; - rspamd_fstring_t *w; + rspamd_ftok_t *w; const guchar *r; gchar *temp_word; guint i, nlen; @@ -971,7 +970,7 @@ rspamd_normalize_text_part (struct rspamd_task *task, if (tmp) { for (i = 0; i < tmp->len; i ++) { - w = &g_array_index (tmp, rspamd_fstring_t, i); + w = &g_array_index (tmp, rspamd_ftok_t, i); if (stem) { r = sb_stemmer_stem (stem, w->begin, w->len); } @@ -980,21 +979,23 @@ rspamd_normalize_text_part (struct rspamd_task *task, if (stem != NULL && r != NULL) { nlen = strlen (r); nlen = MIN (nlen, w->len); - w->begin = rspamd_mempool_alloc (task->task_pool, nlen); - memcpy (w->begin, r, nlen); + temp_word = rspamd_mempool_alloc (task->task_pool, nlen); + memcpy (temp_word, r, nlen); + w->begin = temp_word; w->len = nlen; } else { - temp_word = w->begin; - w->begin = rspamd_mempool_alloc (task->task_pool, w->len); - memcpy (w->begin, temp_word, w->len); + temp_word = rspamd_mempool_alloc (task->task_pool, w->len); + memcpy (temp_word, w->begin, w->len); if (IS_PART_UTF (part)) { - rspamd_str_lc_utf8 (w->begin, w->len); + rspamd_str_lc_utf8 (temp_word, w->len); } else { - rspamd_str_lc (w->begin, w->len); + rspamd_str_lc (temp_word, w->len); } + + w->begin = temp_word; } } } @@ -1463,8 +1464,9 @@ rspamd_message_parse (struct rspamd_task *task) guint tw, dw; tmp = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray)); - p = task->msg.start; + p = task->msg.begin; len = task->msg.len; + /* Skip any space characters to avoid some bad messages to be unparsed */ while (g_ascii_isspace (*p) && len > 0) { p ++; diff --git a/src/libmime/smtp_proto.c b/src/libmime/smtp_proto.c index 988bd37af..d00a25e0f 100644 --- a/src/libmime/smtp_proto.c +++ b/src/libmime/smtp_proto.c @@ -57,7 +57,7 @@ make_smtp_error (rspamd_mempool_t *pool, gboolean parse_smtp_command (struct smtp_session *session, - rspamd_fstring_t *line, + rspamd_ftok_t *line, struct smtp_command **cmd) { enum { @@ -66,9 +66,10 @@ parse_smtp_command (struct smtp_session *session, SMTP_PARSE_ARGUMENT, SMTP_PARSE_DONE } state; - gchar *p, *c, ch, cmd_buf[4]; + const gchar *p, *c; + gchar ch, cmd_buf[4]; guint i; - rspamd_fstring_t *arg = NULL; + rspamd_ftok_t *arg = NULL; struct smtp_command *pcmd; if (line->len == 0) { @@ -176,8 +177,9 @@ parse_smtp_command (struct smtp_session *session, } arg->len = p - c; arg->begin = rspamd_mempool_alloc (session->pool, arg->len); - memcpy (arg->begin, c, arg->len); + memcpy ((gchar *)arg->begin, c, arg->len); pcmd->args = g_list_prepend (pcmd->args, arg); + if (ch == ' ' || ch == ':') { state = SMTP_PARSE_SPACES; } @@ -209,10 +211,10 @@ end: } static gboolean -check_smtp_path (rspamd_fstring_t *path) +check_smtp_path (rspamd_ftok_t *path) { guint i; - gchar *p; + const gchar *p; p = path->begin; if (*p != '<' || path->len < 2) { @@ -230,7 +232,7 @@ check_smtp_path (rspamd_fstring_t *path) gboolean parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd) { - rspamd_fstring_t *arg; + rspamd_ftok_t *arg; if (cmd->args == NULL) { session->error = SMTP_ERROR_BAD_ARGUMENTS; @@ -265,7 +267,7 @@ parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd) gboolean parse_smtp_from (struct smtp_session *session, struct smtp_command *cmd) { - rspamd_fstring_t *arg; + rspamd_ftok_t *arg; GList *cur = cmd->args; if (cmd->args == NULL) { @@ -303,7 +305,7 @@ parse_smtp_from (struct smtp_session *session, struct smtp_command *cmd) gboolean parse_smtp_rcpt (struct smtp_session *session, struct smtp_command *cmd) { - rspamd_fstring_t *arg; + rspamd_ftok_t *arg; GList *cur = cmd->args; if (cmd->args == NULL) { @@ -339,9 +341,9 @@ parse_smtp_rcpt (struct smtp_session *session, struct smtp_command *cmd) /* Return -1 if there are some error, 1 if all is ok and 0 in case of incomplete reply */ static gint -check_smtp_ustream_reply (rspamd_fstring_t *in, gchar success_code) +check_smtp_ustream_reply (rspamd_ftok_t *in, gchar success_code) { - gchar *p; + const gchar *p; /* Check for 250 at the begin of line */ if (in->len >= sizeof ("220 ") - 1) { @@ -368,7 +370,7 @@ smtp_upstream_write_list (GList *args, gchar *buf, size_t buflen) { GList *cur = args; size_t r = 0; - rspamd_fstring_t *arg; + rspamd_ftok_t *arg; while (cur && r < buflen - 3) { arg = cur->data; @@ -401,7 +403,7 @@ smtp_upstream_write_socket (void *arg) } gboolean -smtp_upstream_read_socket (rspamd_fstring_t * in, void *arg) +smtp_upstream_read_socket (rspamd_ftok_t * in, void *arg) { struct smtp_session *session = arg; gchar outbuf[BUFSIZ]; diff --git a/src/libmime/smtp_proto.h b/src/libmime/smtp_proto.h index a0f2ec5c2..7ede6f803 100644 --- a/src/libmime/smtp_proto.h +++ b/src/libmime/smtp_proto.h @@ -24,20 +24,21 @@ #define MAX_SMTP_UPSTREAMS 128 +enum smtp_command_type { + SMTP_COMMAND_HELO = 0, + SMTP_COMMAND_EHLO, + SMTP_COMMAND_QUIT, + SMTP_COMMAND_NOOP, + SMTP_COMMAND_MAIL, + SMTP_COMMAND_RCPT, + SMTP_COMMAND_RSET, + SMTP_COMMAND_DATA, + SMTP_COMMAND_VRFY, + SMTP_COMMAND_EXPN, + SMTP_COMMAND_HELP +}; struct smtp_command { - enum { - SMTP_COMMAND_HELO, - SMTP_COMMAND_EHLO, - SMTP_COMMAND_QUIT, - SMTP_COMMAND_NOOP, - SMTP_COMMAND_MAIL, - SMTP_COMMAND_RCPT, - SMTP_COMMAND_RSET, - SMTP_COMMAND_DATA, - SMTP_COMMAND_VRFY, - SMTP_COMMAND_EXPN, - SMTP_COMMAND_HELP - } command; + enum smtp_command_type command; GList *args; }; @@ -53,7 +54,7 @@ gchar * make_smtp_error (rspamd_mempool_t *pool, * Parse a single SMTP command */ gboolean parse_smtp_command (struct smtp_session *session, - rspamd_fstring_t *line, + rspamd_ftok_t *line, struct smtp_command **cmd); /* @@ -79,7 +80,7 @@ gboolean parse_smtp_rcpt (struct smtp_session *session, /* * Read a line from SMTP upstream */ -gboolean smtp_upstream_read_socket (rspamd_fstring_t * in, void *arg); +gboolean smtp_upstream_read_socket (rspamd_ftok_t * in, void *arg); /* * Write to SMTP upstream diff --git a/src/libmime/smtp_utils.c b/src/libmime/smtp_utils.c index edc7f3b14..df50abc65 100644 --- a/src/libmime/smtp_utils.c +++ b/src/libmime/smtp_utils.c @@ -35,8 +35,9 @@ free_smtp_session (gpointer arg) if (session) { if (session->task) { rspamd_task_free (session->task, FALSE); - if (session->task->msg.start) { - munmap (session->task->msg.start, session->task->msg.len); + if (session->task->msg.begin) { + munmap ((gpointer)session->task->msg.begin, + session->task->msg.len); } } if (session->rcpt) {