Fix possible StackOverflowError when try to resolve authorative names… (#10337)
Motivation: There is a possibility to end up with a StackOverflowError when trying to resolve authorative nameservers because of incorrect wrapping the AuthoritativeDnsServerCache. Modifications: Ensure we don't end up with an overflow due wrapping Result: Fixes https://github.com/netty/netty/issues/10246
This commit is contained in:
parent
21eb936dbe
commit
0bd8771697
@ -498,12 +498,33 @@ abstract class DnsResolveContext<T> {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!DnsNameResolver.doResolveAllCached(nameServerName, additionals, resolverPromise, resolveCache(),
|
||||
DnsCache resolveCache = resolveCache();
|
||||
if (!DnsNameResolver.doResolveAllCached(nameServerName, additionals, resolverPromise, resolveCache,
|
||||
parent.resolvedInternetProtocolFamiliesUnsafe())) {
|
||||
final AuthoritativeDnsServerCache authoritativeDnsServerCache = authoritativeDnsServerCache();
|
||||
new DnsAddressResolveContext(parent, originalPromise, nameServerName, additionals,
|
||||
parent.newNameServerAddressStream(nameServerName),
|
||||
resolveCache(), new AuthoritativeDnsServerCache() {
|
||||
parent.newNameServerAddressStream(nameServerName), resolveCache,
|
||||
redirectAuthoritativeDnsServerCache(authoritativeDnsServerCache()), false)
|
||||
.resolve(resolverPromise);
|
||||
}
|
||||
}
|
||||
|
||||
private static AuthoritativeDnsServerCache redirectAuthoritativeDnsServerCache(
|
||||
AuthoritativeDnsServerCache authoritativeDnsServerCache) {
|
||||
// Don't wrap again to prevent the possibility of an StackOverflowError when wrapping another
|
||||
// RedirectAuthoritativeDnsServerCache.
|
||||
if (authoritativeDnsServerCache instanceof RedirectAuthoritativeDnsServerCache) {
|
||||
return authoritativeDnsServerCache;
|
||||
}
|
||||
return new RedirectAuthoritativeDnsServerCache(authoritativeDnsServerCache);
|
||||
}
|
||||
|
||||
private static final class RedirectAuthoritativeDnsServerCache implements AuthoritativeDnsServerCache {
|
||||
private final AuthoritativeDnsServerCache wrapped;
|
||||
|
||||
RedirectAuthoritativeDnsServerCache(AuthoritativeDnsServerCache authoritativeDnsServerCache) {
|
||||
this.wrapped = authoritativeDnsServerCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DnsServerAddressStream get(String hostname) {
|
||||
// To not risk falling into any loop, we will not use the cache while following redirects but only
|
||||
@ -513,19 +534,17 @@ abstract class DnsResolveContext<T> {
|
||||
|
||||
@Override
|
||||
public void cache(String hostname, InetSocketAddress address, long originalTtl, EventLoop loop) {
|
||||
authoritativeDnsServerCache.cache(hostname, address, originalTtl, loop);
|
||||
wrapped.cache(hostname, address, originalTtl, loop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
authoritativeDnsServerCache.clear();
|
||||
wrapped.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clear(String hostname) {
|
||||
return authoritativeDnsServerCache.clear(hostname);
|
||||
}
|
||||
}, false).resolve(resolverPromise);
|
||||
return wrapped.clear(hostname);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user