commit 86fb42c: [Minor] Lua_url: Another fix for emails to string

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Oct 22 11:14:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-10-22 11:35:22 +0100
URL: https://github.com/rspamd/rspamd/commit/86fb42c53e463bf158525915fc18468f991baeea

[Minor] Lua_url: Another fix for emails to string

---
 src/lua/lua_url.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index bd79c1697..57be4c009 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -302,12 +302,20 @@ lua_url_tostring (lua_State *L)
 
 	if (url != NULL && url->url != NULL) {
 		if (url->url->protocol == PROTOCOL_MAILTO) {
-			if (url->url->userlen + 1 + url->url->hostlen <= url->url->urllen) {
-				lua_pushlstring (L, url->url->user,
-						url->url->userlen + 1 + url->url->hostlen);
+			if (url->url->userlen + 1 + url->url->hostlen == url->url->urllen) {
+				lua_pushlstring (L, url->url->string, url->url->urllen);
 			}
 			else {
-				lua_pushlstring (L, url->url->string, url->url->urllen);
+				/* TODO: not efficient */
+				gchar *tmp = g_malloc (url->url->userlen + 1 +
+						url->url->hostlen);
+				memcpy (tmp, url->url->user, url->url->userlen);
+				tmp[url->url->userlen] = '@';
+				memcpy (tmp + url->url->userlen + 1, url->url->host,
+						url->url->hostlen);
+
+				lua_pushlstring (L, tmp, url->url->userlen + 1 + url->url->hostlen);
+				g_free (tmp);
 			}
 		}
 		else {


More information about the Commits mailing list