aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-11-04 22:13:27 +0600
committerGitHub <noreply@github.com>2024-11-04 22:13:27 +0600
commit78eea16898c25f85a1c866e3cc7d4a57813ec7c4 (patch)
treeb453f9d0ae25b63387f219cee0cf7928f9668d67
parent80cb50dea482246656a49e54a915bdc343ffe897 (diff)
parentc99d053df77144d4cf8e7b276d674530e339c4f6 (diff)
downloadrspamd-78eea16898c25f85a1c866e3cc7d4a57813ec7c4.tar.gz
rspamd-78eea16898c25f85a1c866e3cc7d4a57813ec7c4.zip
Merge pull request #5210 from rspamd/vstakhov-fix-utf8-ragel
[Fix] Another story about char sign
-rw-r--r--src/ragel/smtp_addr_parser.rl18
-rw-r--r--test/lua/unit/smtp_addr.lua68
2 files changed, 44 insertions, 42 deletions
diff --git a/src/ragel/smtp_addr_parser.rl b/src/ragel/smtp_addr_parser.rl
index b5b4863d3..330f3f01d 100644
--- a/src/ragel/smtp_addr_parser.rl
+++ b/src/ragel/smtp_addr_parser.rl
@@ -8,33 +8,33 @@
action IP4_end {}
action User_start {
- addr->user = p;
+ addr->user = (const char *)p;
}
action User_end {
if (addr->user) {
- addr->user_len = p - addr->user;
+ addr->user_len = (const char *)p - addr->user;
}
}
action Domain_start {
- addr->domain = p;
+ addr->domain = (const char *)p;
}
action Domain_end {
if (addr->domain) {
- addr->domain_len = p - addr->domain;
+ addr->domain_len = (const char *)p - addr->domain;
}
}
action Domain_addr_start {
- addr->domain = p;
+ addr->domain = (const char *)p;
addr->flags |= RSPAMD_EMAIL_ADDR_IP;
}
action Domain_addr_end {
if (addr->domain) {
- addr->domain_len = p - addr->domain;
+ addr->domain_len = (const char *)p - addr->domain;
}
}
@@ -64,12 +64,12 @@
}
action Addr_start {
- addr->addr = p;
+ addr->addr = (const char *)p;
}
action Addr_end {
if (addr->addr) {
- addr->addr_len = p - addr->addr;
+ addr->addr_len = (const char *)p - addr->addr;
}
}
@@ -87,7 +87,7 @@
int
rspamd_smtp_addr_parse (const char *data, size_t len, struct rspamd_email_address *addr)
{
- const char *p = data, *pe = data + len, *eof;
+ const unsigned char *p = (const unsigned char *)data, *pe = (const unsigned char *)data + len, *eof;
int cs;
g_assert (addr != NULL);
diff --git a/test/lua/unit/smtp_addr.lua b/test/lua/unit/smtp_addr.lua
index 2cb7755f8..16f59d07c 100644
--- a/test/lua/unit/smtp_addr.lua
+++ b/test/lua/unit/smtp_addr.lua
@@ -5,7 +5,7 @@ context("SMTP address check functions", function()
local ffi = require("ffi")
local util = require("rspamd_util")
local fun = require "fun"
- ffi.cdef[[
+ ffi.cdef [[
struct rspamd_email_address {
const char *raw;
const char *addr;
@@ -24,29 +24,31 @@ context("SMTP address check functions", function()
]]
local cases_valid = {
- {'<>', {addr = ''}},
- {'<a@example.com>', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
- {'<a-b@example.com>', {user = 'a-b', domain = 'example.com', addr = 'a-b@example.com'}},
- {'<a-b@ex-ample.com>', {user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com'}},
- {'1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru',
- {user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370',
- domain = 'example.220-volt.ru',
- addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru'}},
- {'notification+kjdm---m7wwd@facebookmail.com', {user = 'notification+kjdm---m7wwd'}},
- {'a@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
- {'a+b@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
- {'"a"@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
- {'"a+b"@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
- {'"<>"@example.com', {user = '<>', domain = 'example.com', addr = '<>@example.com'}},
- {'<"<>"@example.com>', {user = '<>', domain = 'example.com', addr = '<>@example.com'}},
- {'"\\""@example.com', {user = '"', domain = 'example.com', addr = '"@example.com'}},
- {'"\\"abc"@example.com', {user = '"abc', domain = 'example.com', addr = '"abc@example.com'}},
- {'<@domain1,@domain2,@domain3:abc@example.com>',
- {user = 'abc', domain = 'example.com', addr = 'abc@example.com'}},
+ { '<>', { addr = '' } },
+ { '<a@example.com>', { user = 'a', domain = 'example.com', addr = 'a@example.com' } },
+ { '<a-b@example.com>', { user = 'a-b', domain = 'example.com', addr = 'a-b@example.com' } },
+ { '<a-b@ex-ample.com>', { user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com' } },
+ { '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru',
+ { user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370',
+ domain = 'example.220-volt.ru',
+ addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru' } },
+ { 'notification+kjdm---m7wwd@facebookmail.com', { user = 'notification+kjdm---m7wwd' } },
+ { 'a@example.com', { user = 'a', domain = 'example.com', addr = 'a@example.com' } },
+ { 'a+b@example.com', { user = 'a+b', domain = 'example.com', addr = 'a+b@example.com' } },
+ { '"a"@example.com', { user = 'a', domain = 'example.com', addr = 'a@example.com' } },
+ { '"a+b"@example.com', { user = 'a+b', domain = 'example.com', addr = 'a+b@example.com' } },
+ { '"<>"@example.com', { user = '<>', domain = 'example.com', addr = '<>@example.com' } },
+ { '<"<>"@example.com>', { user = '<>', domain = 'example.com', addr = '<>@example.com' } },
+ { '"\\""@example.com', { user = '"', domain = 'example.com', addr = '"@example.com' } },
+ { '"\\"abc"@example.com', { user = '"abc', domain = 'example.com', addr = '"abc@example.com' } },
+ { '<@domain1,@domain2,@domain3:abc@example.com>',
+ { user = 'abc', domain = 'example.com', addr = 'abc@example.com' } },
+ -- SMTP UTF8
+ { 'ñ@example.com', { user = 'ñ', domain = 'example.com' } },
+ { 'ñ@ололо.лол', { user = 'ñ', domain = 'ололо.лол' } }
}
-
fun.each(function(case)
test("Parse valid smtp addr: " .. case[1], function()
local st = ffi.C.rspamd_email_address_from_smtp(case[1], #case[1])
@@ -69,17 +71,17 @@ context("SMTP address check functions", function()
end)
end, cases_valid)
- local cases_invalid = {
- 'a',
- 'a"b"@example.com',
- 'a"@example.com',
- '"a@example.com',
- '<a@example.com',
- 'a@example.com>',
- '<a@.example.com>',
- '<a@example.com>>',
- '<a@example.com><>',
- }
+ local cases_invalid = {
+ 'a',
+ 'a"b"@example.com',
+ 'a"@example.com',
+ '"a@example.com',
+ '<a@example.com',
+ 'a@example.com>',
+ '<a@.example.com>',
+ '<a@example.com>>',
+ '<a@example.com><>',
+ }
fun.each(function(case)
test("Parse invalid smtp addr: " .. case, function()
@@ -95,7 +97,7 @@ context("SMTP address check functions", function()
local niter = 100000
local total = 0
- for i = 1,niter do
+ for i = 1, niter do
local ncase = string.format(case, i)
local t1 = util.get_ticks()
local st = ffi.C.rspamd_email_address_from_smtp(ncase, #ncase)