[BUGFIX] Resolver: fallback for invalid SRV CNAME entries

This commit is contained in:
genofire 2020-02-10 00:57:58 +01:00
parent a94df45a29
commit c05d0ab574
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 24 additions and 1 deletions

View File

@ -172,6 +172,9 @@ public class Resolver {
ResolverResult<SRV> result = resolveWithFallback(dnsName, SRV.class); ResolverResult<SRV> result = resolveWithFallback(dnsName, SRV.class);
final List<Result> results = new ArrayList<>(); final List<Result> results = new ArrayList<>();
final List<Thread> threads = new ArrayList<>(); final List<Thread> threads = new ArrayList<>();
final List<Result> fallbackResults = new ArrayList<>();
final List<Thread> fallbackThreads = new ArrayList<>();
for (SRV record : result.getAnswersOrEmptySet()) { for (SRV record : result.getAnswersOrEmptySet()) {
if (record.name.length() == 0) { if (record.name.length() == 0) {
continue; continue;
@ -188,6 +191,12 @@ public class Resolver {
results.addAll(ipv4s); results.addAll(ipv4s);
} }
})); }));
fallbackThreads.add(new Thread(() -> {
final List<Result> cnames = resolveIp(record, CNAME.class, result.isAuthenticData(), directTls);
synchronized (fallbackResults) {
fallbackResults.addAll(cnames);
}
}));
} }
for (Thread thread : threads) { for (Thread thread : threads) {
thread.start(); thread.start();
@ -199,7 +208,21 @@ public class Resolver {
return Collections.emptyList(); return Collections.emptyList();
} }
} }
return results; if (results.size() > 0) {
return results;
}
for (Thread thread : fallbackThreads) {
thread.start();
}
for (Thread thread : fallbackThreads) {
try {
thread.join();
} catch (InterruptedException e) {
return Collections.emptyList();
}
}
return fallbackResults;
} }
private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) { private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) {