fix parsing of long TXT records, this prevents 'smtpctl spf walk' from
authorgilles <gilles@openbsd.org>
Thu, 11 Jan 2018 19:20:41 +0000 (19:20 +0000)
committergilles <gilles@openbsd.org>
Thu, 11 Jan 2018 19:20:41 +0000 (19:20 +0000)
producing bogus entries with some SPF records.

ok ajacoutot@

usr.sbin/smtpd/spfwalk.c

index 833841a..64de139 100644 (file)
@@ -145,11 +145,9 @@ dispatch_txt(struct dns_rr *rr)
         char *in = buf;
         char *argv[512];
         char **ap = argv;
-
+       char *end;
+       
        print_dname(rr->rr.other.rdata, buf, sizeof(buf));
-       buf[strlen(buf) - 1] = '\0';
-       if (buf[strlen(buf) - 1] == '.')
-               buf[strlen(buf) - 1] = '\0';
        if (strncasecmp("v=spf1 ", buf, 7))
                return;
 
@@ -157,6 +155,10 @@ dispatch_txt(struct dns_rr *rr)
                if (strcasecmp(*ap, "v=spf1") == 0)
                        continue;
 
+               end = *ap + strlen(*ap)-1;
+               if (*end == '.')
+                       *end = '\0';
+
                if (strncasecmp("ip4:", *ap, 4) == 0) {
                        if (ip_v4 == 1 || ip_both == 1)
                                printf("%s\n", *(ap) + 4);