From: Vsevolod Stakhov Date: Fri, 20 Nov 2020 15:55:39 +0000 (+0000) Subject: [Fix] Fix quoted-printable soft newlines bugged case X-Git-Tag: 2.7~126 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f71dee6d40be52c69f5a90536e811db8e1f852f1;p=rspamd.git [Fix] Fix quoted-printable soft newlines bugged case --- diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 1e7d0b06b..2e1fd6a0d 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -2341,15 +2341,19 @@ decode: if (c >= '0' && c <= '9') { ret = c - '0'; } else if (c >= 'A' && c <= 'F') { ret = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ret = c - 'a' + 10; } - else if (c == '\r' || c == '\n') { - /* Soft line break */ - while (remain > 0 && (*p == '\r' || *p == '\n')) { - remain --; + else if (c == '\r') { + /* Eat one more endline */ + if (remain > 0 && *p == '\n') { p ++; + remain --; } continue; } + else if (c == '\n') { + /* Soft line break */ + continue; + } else { /* Hack, hack, hack, treat = as = */ if (remain > 0) { diff --git a/test/lua/unit/quoted_printable.lua b/test/lua/unit/quoted_printable.lua index cf667f8d4..29df0254d 100644 --- a/test/lua/unit/quoted_printable.lua +++ b/test/lua/unit/quoted_printable.lua @@ -102,6 +102,16 @@ context("Quoted-Printable encoding", function() 'Mailscape External Mail Flow Outbound Test=', 'asan found' }, + { + 'foo=\n\nbar', + 'foo\nbar', + 'Soft newline followed by hard newline (LF)', + }, + { + 'foo=\r\n\r\nbar', + 'foo\r\nbar', + 'Soft newline followed by hard newline (CRLF)', + }, } for _,c in ipairs(cases) do