/* Add metric score */
- if ((s = g_hash_table_lookup (metric_res->symbols, symbol)) != NULL) {
- if (!single) {
- if (s->options && opts && opts != s->options) {
- /* Append new options */
- s->options = g_list_concat (s->options, g_list_copy(opts));
- /*
- * Note that there is no need to add new destructor of GList as elements of appended
- * GList are used directly, so just free initial GList
- */
- }
- else if (opts) {
- s->options = opts;
- memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_list_free, s->options);
- }
-
- s->score += w;
- metric_res->score += w;
+ if (!single && (s = g_hash_table_lookup (metric_res->symbols, symbol)) != NULL) {
+ if (s->options && opts && opts != s->options) {
+ /* Append new options */
+ s->options = g_list_concat (s->options, g_list_copy(opts));
+ /*
+ * Note that there is no need to add new destructor of GList as elements of appended
+ * GList are used directly, so just free initial GList
+ */
}
+ else if (opts) {
+ s->options = g_list_copy (opts);
+ memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_list_free, s->options);
+ }
+
+ s->score += w;
+ metric_res->score += w;
}
else {
s = memory_pool_alloc (task->task_pool, sizeof (struct symbol));
s->score = w;
- s->options = opts;
+
s->name = symbol;
metric_res->score += w;
if (opts) {
+ s->options = g_list_copy (opts);
memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_list_free, s->options);
}
+ else {
+ s->options = NULL;
+ }
g_hash_table_insert (metric_res->symbols, (gpointer) symbol, s);
}
cur = g_list_next (cur);
}
}
+
+ if (opts != NULL) {
+ /* XXX: it is not wise to destroy them here */
+ g_list_free (opts);
+ }
}
/* Insert result that may be increased on next insertions */
}
static void
-check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url_text)
+check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url_text, gsize remain)
{
struct uri *new;
gchar *url_str;
- gsize len;
+ const gchar *p;
+ gsize len = 0;
gint off, rc;
- len = strcspn (url_text, "<>");
+ p = url_text;
+ while (len < remain) {
+ if (*p == '<' || *p == '>') {
+ break;
+ }
+ len ++;
+ p ++;
+ }
if (url_try_text (task->task_pool, url_text, len, &off, &url_str) && url_str != NULL) {
new = memory_pool_alloc0 (task->task_pool, sizeof (struct uri));
* Check for phishing
*/
if ((p = strchr (c, '>')) != NULL ) {
- check_phishing (task, url, p + 1);
+ check_phishing (task, url, p + 1, tag_len - (p - tag_text));
}
if (part->html_urls && g_tree_lookup (part->html_urls, url_text) == NULL) {
g_tree_insert (part->html_urls, url_text, url);
msg_err ("endless recursion detected: %d", task->parser_recursion);
return;
}
+#ifndef GMIME24
g_object_unref (message);
+#endif
}
else if (GMIME_IS_MESSAGE_PARTIAL (part)) {
/* message/partial */
guint8 *ct;
gsize clen;
gint r, passed = 0, start, end, old;
- gboolean matched;
+ gboolean matched = FALSE;
GList *cur, *headerlist;
GRegex *regexp;
}
cur = g_list_previous (cur);
}
- if (record->addrs != NULL) {
- /* Free addresses that we already proceed */
- g_list_free (record->addrs);
- record->addrs = NULL;
- }
}
if (task->save.saved == 0) {
msg_info ("spf record: %s", logbuf);
}
+/*
+ * Destructor for spf record
+ */
+static void
+spf_record_destructor (gpointer r)
+{
+ struct spf_record *rec = r;
+
+ if (rec->addrs) {
+ g_list_free (rec->addrs);
+ }
+}
+
static gboolean
parse_spf_ipmask (const gchar *begin, struct spf_addr *addr)
{
else if (reply->type == DNS_REQUEST_A) {
if (cb->addr->addr == 0) {
cb->addr->addr = ntohl (elt_data->a.addr[0].s_addr);
+ cb->addr->mask = 32;
}
else {
/* Insert one more address */
if (reply->type == DNS_REQUEST_A) {
/* XXX: process only one record */
cb->addr->addr = ntohl (elt_data->a.addr[0].s_addr);
+ cb->addr->mask = 32;
}
break;
case SPF_RESOLVE_PTR:
start_spf_parse (cb->rec, begin);
cb->rec->in_include = FALSE;
- if (tmp) {
+ if (tmp && cb->rec->addrs) {
tmp1 = g_list_find (tmp, cb->addr);
if (tmp1) {
/* Insert new list in place of include element */
+ cb->rec->addrs->prev = tmp1->prev;
last = g_list_last (cb->rec->addrs);
-
- if (tmp1->prev == NULL && tmp1->next == NULL) {
- g_list_free1 (tmp1);
+ last->next = tmp1;
+ tmp1->prev = last;
+ /* If tmp1 is at the beginning of the list, shift list */
+ if (tmp == tmp1) {
+ tmp = cb->rec->addrs;
}
else {
-
- if (tmp1->prev) {
- tmp1->prev->next = cb->rec->addrs;
- }
- else {
- /* Elt is the first element, so we need to shift temporary list */
- tmp = tmp1->next;
- tmp->prev = NULL;
- }
- if (tmp1->next) {
- tmp1->next->prev = last;
- if (last != NULL) {
- last->next = tmp1->next;
- }
- }
-
- if (cb->rec->addrs != NULL) {
- cb->rec->addrs->prev = tmp1->prev;
- }
-
- /* Shift temporary list */
- while (tmp->prev) {
- tmp = tmp->prev;
- }
-
- cb->rec->addrs = tmp;
- g_list_free1 (tmp1);
+ tmp1->prev->next = cb->rec->addrs;
+ }
+ /* Remove self element */
+ tmp = g_list_delete_link (tmp, tmp1);
#ifdef SPF_DEBUG
- msg_info ("after include");
- dump_spf_record (cb->rec->addrs);
+ msg_info ("after include");
+ dump_spf_record (cb->rec->addrs);
#endif
- }
}
}
+ if (tmp) {
+ cb->rec->addrs = tmp;
+ }
}
break;
case SPF_RESOLVE_EXP:
if (reply->type == DNS_REQUEST_MX) {
msg_info ("cannot find MX record for %s", cb->rec->cur_domain);
cb->addr->addr = ntohl (INADDR_NONE);
+ cb->addr->mask = 32;
}
else if (reply->type != DNS_REQUEST_MX) {
msg_info ("cannot resolve MX record for %s", cb->rec->cur_domain);
cb->addr->addr = ntohl (INADDR_NONE);
+ cb->addr->mask = 32;
}
break;
case SPF_RESOLVE_A:
if (reply->type == DNS_REQUEST_A) {
/* XXX: process only one record */
cb->addr->addr = ntohl (INADDR_NONE);
+ cb->addr->mask = 32;
}
break;
case SPF_RESOLVE_PTR:
break;
case SPF_RESOLVE_EXISTS:
cb->addr->addr = ntohl (INADDR_NONE);
+ cb->addr->mask = 32;
break;
}
}
(x) = memory_pool_alloc (task->task_pool, sizeof (struct spf_addr)); \
(x)->mech = check_spf_mech (rec->cur_elt, &need_shift); \
(x)->spf_string = memory_pool_strdup (task->task_pool, begin); \
+ (x)->addr = 0; \
+ (x)->mask = 32; \
} while (0);
/* Read current element and try to parse record */
rec = memory_pool_alloc0 (task->task_pool, sizeof (struct spf_record));
rec->task = task;
rec->callback = callback;
+ /* Add destructor */
+ memory_pool_add_destructor (task->task_pool, (pool_destruct_func)spf_record_destructor, rec);
+ /* Extract from data */
if (task->from && (domain = strchr (task->from, '@')) != NULL && *domain == '@') {
rec->sender = task->from;
}
}
else {
+ /* Extract from header */
domains = message_get_header (task->task_pool, task->message, "From", FALSE);
if (domains != NULL) {
}
}
- while (p < end && *p != stop && is_urlsafe (*p)) {
+ while (p < end - 1 && *p != stop && is_urlsafe (*p)) {
p ++;
}
if (is_atom (*p)) {
/* might be a domain or user@domain */
c = p;
- while (p < end) {
+ while (p < end - 1) {
if (!is_atom (*p)) {
break;
}
p++;
- while (p < end && is_atom (*p)) {
+ while (p < end - 1 && is_atom (*p)) {
p++;
}
}
else if (is_domain (*p)) {
domain:
- while (p < end) {
+ while (p < end - 1) {
if (!is_domain (*p)) {
break;
}
p++;
- while (p < end && is_domain (*p)) {
+ while (p < end - 1 && is_domain (*p)) {
p++;
}
- if ((p + 1) < end && *p == '.' && (is_domain (*(p + 1)) || *(p + 1) == '/')) {
+ if ((p + 1) < end - 1 && *p == '.' && (is_domain (*(p + 1)) || *(p + 1) == '/')) {
p++;
}
}
if (is_digit (*p) || passwd) {
port = (*p++ - '0');
- while (p < end && is_digit (*p) && port < 65536) {
+ while (p < end - 1 && is_digit (*p) && port < 65536) {
port = (port * 10) + (*p++ - '0');
}
passwd = TRUE;
c = p;
- while (p < end && is_atom (*p)) {
+ while (p < end - 1 && is_atom (*p)) {
p++;
}
case '/': /* we've detected a path component to our url */
p++;
case '?':
- while (p < end && is_urlsafe (*p)) {
+ while (p < end - 1 && is_urlsafe (*p)) {
if (*p == open_brace) {
brace_stack++;
}