diff src/dnsbl.cpp @ 337:d68fda9be1c1

need to convert nl and tab to spaces in header values before regexec
author Carl Byington <carl@five-ten-sg.com>
date Tue, 20 Dec 2016 17:13:48 -0800
parents 354b15b8b263
children f375a67ee516
line wrap: on
line diff
--- a/src/dnsbl.cpp	Tue Dec 20 16:59:40 2016 -0800
+++ b/src/dnsbl.cpp	Tue Dec 20 17:13:48 2016 -0800
@@ -1463,6 +1463,13 @@
 {
     mlfiPriv &priv = *MLFIPRIV;
     priv.header_count++;
+    char *value = headerv;
+    if ((priv.header_count < 4) || (strcasecmp(headerf, "from") == 0)) {
+        for (size_t i=0; i<strlen(value); i++) {
+            if (value[i] < 0x20) value[i] = ' ';
+        }
+    }
+
     if (priv.dkim_ok) {
         if ((priv.header_count == 1) && (strcasecmp(headerf, "DKIM-Filter") != 0)) priv.dkim_ok = false;
         if (priv.header_count == 2) {
@@ -1471,17 +1478,16 @@
             if (priv.dkim_ok) {
                 const int nmatch = 2;
                 regmatch_t match[nmatch];
-                char *msgo = headerv;
                 while (true) {
-                    if (0 == regexec(&dkim_pattern, msgo, nmatch, match, 0)) {
+                    if (0 == regexec(&dkim_pattern, value, nmatch, match, 0)) {
                         int s1 = match[1].rm_so;    // domain
                         int e1 = match[1].rm_eo;
                         if (s1 != -1) {
-                            char save = msgo[e1];
-                            msgo[e1] = '\0';
-                            priv.dkim_signers.insert(strdup(msgo+s1));
-                            msgo[e1] = save;
-                            msgo += e1 + 1;
+                            char save = value[e1];
+                            value[e1] = '\0';
+                            priv.dkim_signers.insert(strdup(value+s1));
+                            value[e1] = save;
+                            value += e1 + 1;
                         }
                         else break;
                     }
@@ -1495,15 +1501,13 @@
     if ((!priv.fromaddr) && (strcasecmp(headerf, "from") == 0)) {
         const int nmatch = 2;
         regmatch_t match[nmatch];
-        int err = regexec(&from_pattern, headerv, nmatch, match, 0);
+        int err = regexec(&from_pattern, value, nmatch, match, 0);
         if (err == 0) {
             int s1 = match[1].rm_so;    // domain
             int e1 = match[1].rm_eo;
             if (s1 != -1) {
-                char save = headerv[e1];
-                headerv[e1] = '\0';
-                priv.fromaddr = strdup(headerv+s1);
-                headerv[e1] = save;
+                value[e1] = '\0';
+                priv.fromaddr = strdup(value+s1);
             }
         }
     }