]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix quoted-printable soft newlines bugged case
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 20 Nov 2020 15:55:39 +0000 (15:55 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 20 Nov 2020 15:55:39 +0000 (15:55 +0000)
src/libutil/str_util.c
test/lua/unit/quoted_printable.lua

index 1e7d0b06b6cefe9f47bac0bc7e5e865f1d043558..2e1fd6a0d3b382af4ed50bce5bd97011d92424f3 100644 (file)
@@ -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 =<garbadge> as =<garbadge> */
                                if (remain > 0) {
index cf667f8d44cafdca763119fbb477c107f66a1a5f..29df0254ded282d34991f980bce8f2c9abbab264 100644 (file)
@@ -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