You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2015/08/11 01:43:54 UTC
svn commit: r1695182 - in /spamassassin/trunk/lib/Mail/SpamAssassin/Plugin:
ASN.pm AskDNS.pm URIDNSBL.pm
Author: mmartinec
Date: Mon Aug 10 23:43:53 2015
New Revision: 1695182
URL: http://svn.apache.org/r1695182
Log:
Bug 7236: Net::DNS assumes strings in TXT resource records are in UTF-8 and gratuitously tries to decodes it
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm?rev=1695182&r1=1695181&r2=1695182&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm Mon Aug 10 23:43:53 2015
@@ -355,8 +355,10 @@ sub process_dns_result {
foreach my $rr (@answer) {
dbg("asn: %s: lookup result packet: %s", $zone, $rr->string);
next if $rr->type ne 'TXT';
- my @strings = $rr->char_str_list;
+ my @strings = Net::DNS->VERSION >= 0.69 ? $rr->txtdata
+ : $rr->char_str_list;
next if !@strings;
+ for (@strings) { utf8::encode($_) if utf8::is_utf8($_) }
my @items;
if (@strings > 1 && join('',@strings) !~ m{\|}) {
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm?rev=1695182&r1=1695181&r2=1695182&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm Mon Aug 10 23:43:53 2015
@@ -574,6 +574,7 @@ sub process_response_packet {
if ($rr_rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/) {
$rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rr_rdatastr);
}
+
} elsif ($rr->UNIVERSAL::can('txtdata')) {
# TXT, SPF: join with no intervening spaces, as per RFC 5518
if ($txtdata_can_provide_a_list || $rr_type ne 'TXT') {
@@ -581,10 +582,22 @@ sub process_response_packet {
} else { # char_str_list() is only available for TXT records
$rr_rdatastr = join('', $rr->char_str_list); # historical
}
+ # Net::DNS attempts to decode text strings in a TXT record as UTF-8,
+ # which is bad: octets failing the UTF-8 decoding are converted to
+ # three octets \x{EF}\x{BF}\x{BD} (i.e. to a Unicode "replacement
+ # character" U+FFFD encoded as UTF-8), and ASCII text is unnecessarily
+ # flagged as perl native characters (utf8 flag on), which can be
+ # disruptive on later processing, e.g. implicitly upgrading strings
+ # on concatenation. Unfortunately there is no way of legally bypassing
+ # the UTF-8 decoding by Net::DNS::RR::TXT in Net::DNS::RR::Text.
+ # Try to minimize damage by encoding back to UTF-8 octets:
+ utf8::encode($rr_rdatastr) if utf8::is_utf8($rr_rdatastr);
+
} else {
# rdatastr() is historical, use rdstring() since Net::DNS 0.69
$rr_rdatastr = $rr->UNIVERSAL::can('rdstring') ? $rr->rdstring
: $rr->rdatastr;
+ utf8::encode($rr_rdatastr) if utf8::is_utf8($rr_rdatastr);
}
# dbg("askdns: received rr type %s, data: %s", $rr_type, $rr_rdatastr);
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm?rev=1695182&r1=1695181&r2=1695182&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm Mon Aug 10 23:43:53 2015
@@ -1108,6 +1108,7 @@ sub complete_dnsbl_lookup {
# avoid space-separated RDATA <character-string> fields if possible;
# txtdata provides a list of strings in list context since Net::DNS 0.69
$rdatastr = join('',$rr->txtdata);
+ utf8::encode($rdatastr) if utf8::is_utf8($rdatastr);
} else {
next;
}