From: Vsevolod Stakhov Date: Sun, 29 Nov 2015 19:07:41 +0000 (+0000) Subject: Avoid treating of URLs as zero terminated strings X-Git-Tag: 1.1.0~449 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d9777316bfbfd8194cb94c1615dfa488360da674;p=rspamd.git Avoid treating of URLs as zero terminated strings --- diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index 89def6af7..8f3f6d041 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -772,13 +772,13 @@ tree_url_callback (gpointer key, gpointer value, void *data) task = param->task; ret = rspamd_mime_regexp_element_process (param->task, param->re, - struri (url), 0, FALSE); + url->string, url->urllen, FALSE); param->found = ret; if (G_UNLIKELY (param->re->is_test)) { - msg_info_task ("process test regexp %s for url %s returned FALSE", - param->re->regexp_text, struri (url)); + msg_info_task ("process test regexp %s for url %*s returned FALSE", + param->re->regexp_text, url->urllen, url->string); } } diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 5cd3589f6..d6acd6e74 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -667,12 +667,12 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud) } } - msg_info_task ("<%s> %s: %s; ip: %s; URL: %s", + msg_info_task ("<%s> %s: %s; ip: %s; URL: %*s", task->message_id, has_user ? "user" : "from", user_field, rspamd_inet_address_to_string (task->from_addr), - struri (url)); + url->urllen, url->string); } } diff --git a/src/libserver/url.h b/src/libserver/url.h index 26e994e44..ad373f75b 100644 --- a/src/libserver/url.h +++ b/src/libserver/url.h @@ -60,8 +60,6 @@ enum rspamd_url_protocol { PROTOCOL_UNKNOWN }; -#define struri(uri) ((uri)->string) - /** * Initialize url library * @param cfg diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 020556f35..fc7ff6989 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -894,8 +894,8 @@ make_surbl_requests (struct rspamd_url *url, struct rspamd_task *task, if (surbl_req == NULL) { if (err != NULL) { if (err->code != WHITELIST_ERROR && err->code != DUPLICATE_ERROR) { - msg_info_task ("cannot format url string for surbl %s, %e", - struri (url), + msg_info_task ("cannot format url string for surbl %*s, %e", + url->urllen, url->string, err); } g_error_free (err); @@ -942,8 +942,9 @@ make_surbl_requests (struct rspamd_url *url, struct rspamd_task *task, } else if (err != NULL) { if (err->code != WHITELIST_ERROR && err->code != DUPLICATE_ERROR) { - msg_info_task ("cannot format url string for surbl %s, %e", struri ( - url), err); + msg_info_task ("cannot format url string for surbl %*s, %e", + url->urllen, + url->string, err); } g_error_free (err); return; @@ -1106,15 +1107,13 @@ surbl_redirector_finish (struct rspamd_http_connection *conn, task = param->task; - g_hash_table_remove (param->tree, struri (param->url)); - if (msg->code == 200) { hdr = rspamd_http_message_find_header (msg, "Uri"); if (hdr != NULL) { - msg_info_task ("<%s> got reply from redirector: '%s' -> '%T'", + msg_info_task ("<%s> got reply from redirector: '%*s' -> '%T'", param->task->message_id, - struri (param->url), + param->url->urllen, param->url->string, hdr); urllen = hdr->len; urlstr = rspamd_mempool_alloc (task->task_pool, @@ -1138,9 +1137,9 @@ surbl_redirector_finish (struct rspamd_http_connection *conn, } } else { - msg_info_task ("<%s> could not resolve '%s' on redirector", + msg_info_task ("<%s> could not resolve '%*s' on redirector", param->task->message_id, - struri (param->url)); + param->url->urllen, param->url->string); } rspamd_upstream_ok (param->redirector); @@ -1187,7 +1186,7 @@ register_redirector_call (struct rspamd_url *url, struct rspamd_task *task, RSPAMD_HTTP_CLIENT_SIMPLE, RSPAMD_HTTP_CLIENT, NULL); msg = rspamd_http_new_message (HTTP_REQUEST); - msg->url = rspamd_fstring_assign (msg->url, struri (url), strlen (struri (url))); + msg->url = rspamd_fstring_assign (msg->url, url->string, url->urllen); param->sock = s; param->suffix = suffix; param->redirector = selected; @@ -1204,9 +1203,9 @@ register_redirector_call (struct rspamd_url *url, struct rspamd_task *task, NULL, param, s, timeout, task->ev_base); msg_info_task ( - "<%s> registered redirector call for %s to %s, according to rule: %s", + "<%s> registered redirector call for %*s to %s, according to rule: %s", task->message_id, - struri (url), + url->urllen, url->string, rspamd_upstream_name (param->redirector), rule); } @@ -1235,7 +1234,7 @@ surbl_tree_url_callback (gpointer key, gpointer value, void *data) gboolean found = FALSE; task = param->task; - debug_task ("check url %s", struri (url)); + debug_task ("check url %*s", url->urllen, url->string); if (url->hostlen <= 0) { return; @@ -1273,16 +1272,11 @@ surbl_tree_url_callback (gpointer key, gpointer value, void *data) g_list_prepend (NULL, rspamd_mempool_strdup (task->task_pool, pat->ptr))); } - - if (g_hash_table_lookup (param->tree, struri (url)) == NULL) { - g_hash_table_insert (param->tree, struri (url), url); - - register_redirector_call (url, - param->task, - param->suffix, - pat->ptr, - param->tree); - } + register_redirector_call (url, + param->task, + param->suffix, + pat->ptr, + param->tree); return; }