return FALSE;
}
+static const guint max_domain_length = 253;
+static const guint max_dns_label = 63;
+static const guint max_email_user = 64;
+
static gint
rspamd_mailto_parse (struct http_parser_url *u,
const gchar *str, gsize len,
while (p < last) {
t = *p;
+ if (p - str > max_email_user + max_domain_length + 1) {
+ goto out;
+ }
+
switch (st) {
case parse_mailto:
if (t == ':') {
else if (!is_mailsafe (t)) {
goto out;
}
+ else if (p - c > max_email_user) {
+ goto out;
+ }
p++;
break;
case parse_at:
else if (!is_domain (t) && t != '.' && t != '_') {
goto out;
}
+ else if (p - c > max_domain_length) {
+ goto out;
+ }
p++;
break;
case parse_suffix_question:
while (p < last) {
t = *p;
+ if (p - str > max_email_user) {
+ goto out;
+ }
+
switch (st) {
case parse_protocol:
if (t == ':') {
{
const gchar *p = str, *c = str, *last = str + len, *slash = NULL,
*password_start = NULL, *user_start = NULL;
- gchar t;
+ gchar t = 0;
UChar32 uc;
glong pt;
gint ret = 1;
else if (!g_ascii_isgraph (t)) {
goto out;
}
+ else if (p - c > max_email_user) {
+ goto out;
+ }
+
p++;
break;
case parse_multiple_at:
else if (!g_ascii_isgraph (t)) {
goto out;
}
+ else if (p - c > max_domain_length) {
+ goto out;
+ }
p++;
break;
case parse_at:
}
break;
case parse_domain:
+ if (p - c > max_domain_length) {
+ /* Too large domain */
+ goto out;
+ }
if (t == '/' || t == ':' || t == '?' || t == '#') {
if (p - c == 0) {
goto out;
st = parse_part;
c = p + 1;
}
- else if (!user_seen) {
+ else if (t == ':' && !user_seen) {
/*
* Here we can have both port and password, hence we need
* to apply some heuristic here
p++;
}
else {
- if (is_url_end (t)) {
+ if (is_url_end (t) || is_url_start (t)) {
goto set;
}
else if (*p == '@' && !user_seen) {
}
match->m_len = (last - pos);
+ cb->fin = last + 1;
return TRUE;
}
}
cb->start = m.m_begin;
- cb->fin = pos;
+
+ if (pos > cb->fin) {
+ cb->fin = pos;
+ }
return 1;
}
}
cb->start = m.m_begin;
- cb->fin = pos;
+
+ if (pos > cb->fin) {
+ cb->fin = pos;
+ }
+
url = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_url));
g_strstrip (cb->url_str);
rc = rspamd_url_parse (url, cb->url_str,