Workaround Android bug that cause AbstractDnsRecord to throw when the name is only a ROOT label (#10039)

Motivation:

Having only the ROOT label (".") as the name is valid, but Android 9 and prior does not correctly handle the case. We should add a workaround for it.

Modifications:

Detect if we are on Android and if so check if the name is the ROOT label and if so just return the name without trying to convert it

Result:

Fixes https://github.com/netty/netty/issues/10034
This commit is contained in:
Norman Maurer 2020-02-18 15:05:52 +01:00
parent b2dbd4cedf
commit 59414bfa8c

View File

@ -15,6 +15,7 @@
*/
package io.netty.handler.codec.dns;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;
@ -68,12 +69,23 @@ public abstract class AbstractDnsRecord implements DnsRecord {
// See:
// - https://github.com/netty/netty/issues/4937
// - https://github.com/netty/netty/issues/4935
this.name = appendTrailingDot(IDN.toASCII(requireNonNull(name, "name")));
this.name = appendTrailingDot(IDNtoASCII(name));
this.type = requireNonNull(type, "type");
this.dnsClass = (short) dnsClass;
this.timeToLive = timeToLive;
}
private static String IDNtoASCII(String name) {
requireNonNull(name, "name");
if (PlatformDependent.isAndroid() && DefaultDnsRecordDecoder.ROOT.equals(name)) {
// Prior Android 10 there was a bug that did not correctly parse ".".
//
// See https://github.com/netty/netty/issues/10034
return name;
}
return IDN.toASCII(name);
}
private static String appendTrailingDot(String name) {
if (name.length() > 0 && name.charAt(name.length() - 1) != '.') {
return name + '.';