commit ca59cf9: [Fix] Try to avoid a corner case for `@` pattern

Vsevolod Stakhov vsevolod at rspamd.com
Thu Aug 4 20:56:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-08-04 21:50:12 +0100
URL: https://github.com/rspamd/rspamd/commit/ca59cf9fcb46675c8f455fa6fb709d2357af6111 (HEAD -> master)

[Fix] Try to avoid a corner case for `@` pattern
Issue: #4217

---
 src/libserver/url.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/libserver/url.c b/src/libserver/url.c
index 22bd60a43..62f21e367 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -2489,23 +2489,30 @@ rspamd_url_parse (struct rspamd_url *uri,
 		}
 
 		if (uri->tldlen == 0) {
-			if (!(parse_flags & RSPAMD_URL_PARSE_HREF)) {
-				/* Ignore URL's without TLD if it is not a numeric URL */
-				if (!rspamd_url_is_ip (uri, pool)) {
-					return URI_ERRNO_TLD_MISSING;
-				}
-			} else {
-				if (!rspamd_url_is_ip (uri, pool)) {
-					/* Assume tld equal to host */
-					uri->tldshift = uri->hostshift;
-					uri->tldlen = uri->hostlen;
-				}
-				else if (uri->flags & RSPAMD_URL_FLAG_SCHEMALESS) {
-					/* Ignore urls with both no schema and no tld */
-					return URI_ERRNO_TLD_MISSING;
+			if (uri->protocol != PROTOCOL_MAILTO) {
+				if (!(parse_flags & RSPAMD_URL_PARSE_HREF)) {
+					/* Ignore URL's without TLD if it is not a numeric URL */
+					if (!rspamd_url_is_ip(uri, pool)) {
+						return URI_ERRNO_TLD_MISSING;
+					}
 				}
+				else {
+					if (!rspamd_url_is_ip(uri, pool)) {
+						/* Assume tld equal to host */
+						uri->tldshift = uri->hostshift;
+						uri->tldlen = uri->hostlen;
+					}
+					else if (uri->flags & RSPAMD_URL_FLAG_SCHEMALESS) {
+						/* Ignore urls with both no schema and no tld */
+						return URI_ERRNO_TLD_MISSING;
+					}
 
-				uri->flags |= RSPAMD_URL_FLAG_NO_TLD;
+					uri->flags |= RSPAMD_URL_FLAG_NO_TLD;
+				}
+			}
+			else {
+				/* Ignore IP like domains for mailto, as it is really never supported */
+				return URI_ERRNO_TLD_MISSING;
 			}
 		}
 
@@ -2980,10 +2987,12 @@ url_email_end (struct url_callback_data *cb,
 			return FALSE;
 		}
 
+		/* Check the next character after `@` */
 		if (!g_ascii_isalnum (pos[1]) || !g_ascii_isalnum (*(pos - 1))) {
 			return FALSE;
 		}
 
+
 		c = pos - 1;
 		while (c > cb->begin) {
 			if (!is_mailsafe (*c)) {


More information about the Commits mailing list