DNS: Correctly handle broken SRV records

where the SRV RR points to a target DNS name with no associated A or
AAAA RRs.

Fixes SMACK-781.
references
Florian Schmaus 5 years ago
parent 122bf06ccc
commit 01aa6d9c18
  1. 14
      smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
  2. 9
      smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java
  3. 8
      smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java
  4. 9
      smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java

@ -59,6 +59,20 @@ public abstract class DNSResolver {
return new HostAddress(name, port, inetAddresses);
}
/**
* Lookup the IP addresses of a given host name. Returns <code>null</code> if there was an error, in which the error
* reason will be added in form of a <code>HostAddress</code> to <code>failedAddresses</code>. Returns a empty list
* in case the DNS name exists but has no associated A or AAAA resource records. Otherwise, if the resolution was
* successful <em>and</em> there is at least one A or AAAA resource record, then a non-empty list will be returned.
* <p>
* Concrete DNS resolver implementations are free to overwrite this, but have to stick to the interface contract.
* </p>
*
* @param name the DNS name to lookup
* @param failedAddresses a list with the failed addresses
* @param dnssecMode the selected DNSSEC mode
* @return A list, either empty or non-empty, or <code>null</code>
*/
protected List<InetAddress> lookupHostAddress0(String name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) {
// Default implementation of a DNS name lookup for A/AAAA records. It is assumed that this method does never
// support DNSSEC. Subclasses are free to override this method.

@ -19,6 +19,7 @@ package org.jivesoftware.smack.util.dns.dnsjava;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode;
import org.jivesoftware.smack.initializer.SmackInitializer;
@ -73,7 +74,13 @@ public class DNSJavaResolver extends DNSResolver implements SmackInitializer {
int weight = srvRecord.getWeight();
List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode);
if (hostAddresses == null) {
if (hostAddresses == null || hostAddresses.isEmpty()) {
// If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not
// have any A or AAAA resource records.
if (hostAddresses.isEmpty()) {
LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + host
+ ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup.");
}
continue;
}

@ -111,7 +111,13 @@ public class JavaxResolver extends DNSResolver implements SmackInitializer {
String host = srvRecordEntries[srvRecordEntries.length - 1];
List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode);
if (hostAddresses == null) {
if (hostAddresses == null || hostAddresses.isEmpty()) {
// If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not
// have any A or AAAA resource records.
if (hostAddresses.isEmpty()) {
LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + host
+ ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup.");
}
continue;
}

@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode;
import org.jivesoftware.smack.initializer.SmackInitializer;
@ -90,7 +91,13 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer {
for (SRV srv : result.getAnswers()) {
String hostname = srv.name.ace;
List<InetAddress> hostAddresses = lookupHostAddress0(hostname, failedAddresses, dnssecMode);
if (hostAddresses == null) {
if (hostAddresses == null || hostAddresses.isEmpty()) {
// If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not
// have any A or AAAA resource records.
if (hostAddresses.isEmpty()) {
LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + hostname
+ ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup.");
}
continue;
}

Loading…
Cancel
Save