From: Art Cancro Date: Wed, 10 Feb 2021 16:55:43 +0000 (-0500) Subject: Filter out zero-length MX records X-Git-Tag: v939~120 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=ea55c1f82ea74c3837ad694c238f40744044aed7 Filter out zero-length MX records --- diff --git a/citadel/domain.c b/citadel/domain.c index 25a4d7afc..3c4f1455c 100644 --- a/citadel/domain.c +++ b/citadel/domain.c @@ -155,7 +155,6 @@ int getmx(char *mxbuf, char *dest) { } while(1) { - TRACE; memset(expanded_buf, 0, sizeof(expanded_buf)); ret = dn_expand(startptr, endptr, ptr, expanded_buf, sizeof(expanded_buf)); if (ret < 0) break; @@ -165,7 +164,6 @@ int getmx(char *mxbuf, char *dest) { ptr += INT16SZ + INT32SZ; GETSHORT(n, ptr); - syslog(LOG_DEBUG, "\033[35mgetmx: found record of type %d and length %d\033[0m", type, n); if (type != T_MX) { ptr += n; } @@ -175,16 +173,20 @@ int getmx(char *mxbuf, char *dest) { ret = dn_expand(startptr, endptr, ptr, expanded_buf, sizeof(expanded_buf)); ptr += ret; - ++num_mxrecs; - if (mxrecs == NULL) { - mxrecs = malloc(sizeof(struct mx)); - } - else { - mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) ); - } + // If there are no MX records for the domain, resolv will give us a single one with zero length. + // Make sure we only record actual MX records and not the blank. + if (strlen(expanded_buf) > 0) { + ++num_mxrecs; + if (mxrecs == NULL) { + mxrecs = malloc(sizeof(struct mx)); + } + else { + mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) ); + } - mxrecs[num_mxrecs - 1].pref = pref; - strcpy(mxrecs[num_mxrecs - 1].host, expanded_buf); + mxrecs[num_mxrecs - 1].pref = pref; + strcpy(mxrecs[num_mxrecs - 1].host, expanded_buf); + } } } } @@ -196,7 +198,6 @@ int getmx(char *mxbuf, char *dest) { strcpy(mxbuf, ""); for (n=0; n\033[0m", n, mxrecs[n].host); strcat(mxbuf, mxrecs[n].host); strcat(mxbuf, "|"); } diff --git a/citadel/modules/smtp/serv_smtpclient.c b/citadel/modules/smtp/serv_smtpclient.c index e31581fa1..e18fe563f 100644 --- a/citadel/modules/smtp/serv_smtpclient.c +++ b/citadel/modules/smtp/serv_smtpclient.c @@ -300,7 +300,7 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res try_this_mx, CtdlGetConfigStr("c_fqdn") ); curl_easy_setopt(curl, CURLOPT_URL, smtp_url); - syslog(LOG_DEBUG, "smtpclient: trying mx %d of %d <%s>", i, num_mx, smtp_url); // send the message + syslog(LOG_DEBUG, "smtpclient: trying MX %d of %d <%s>", i+1, num_mx, smtp_url); // send the message res = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); syslog(LOG_DEBUG,