Ignore invalid entries in /etc/resolv.conf when parsing (#9697)
Motivation: We should just ignore (and so skip) invalid entries in /etc/resolver.conf. Modifications: - Skip invalid entries - Add unit test Result: Fix https://github.com/netty/netty/issues/9684
This commit is contained in:
parent
e745ef0645
commit
c7441f68f3
@ -167,6 +167,7 @@ public final class UnixResolverDnsServerAddressStreamProvider implements DnsServ
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
line = line.trim();
|
||||
try {
|
||||
char c;
|
||||
if (line.isEmpty() || (c = line.charAt(0)) == '#' || c == ';') {
|
||||
continue;
|
||||
@ -208,7 +209,10 @@ public final class UnixResolverDnsServerAddressStreamProvider implements DnsServ
|
||||
}
|
||||
port = Integer.parseInt(line.substring(i));
|
||||
} else if (line.startsWith(SORTLIST_ROW_LABEL)) {
|
||||
logger.info("row type {} not supported. ignoring line: {}", SORTLIST_ROW_LABEL, line);
|
||||
logger.info("row type {} not supported. Ignoring line: {}", SORTLIST_ROW_LABEL, line);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.warn("Could not parse entry. Ignoring line: {}", line, e);
|
||||
}
|
||||
}
|
||||
if (!addresses.isEmpty()) {
|
||||
|
@ -164,6 +164,19 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
||||
assertEquals(Collections.singletonList("squarecorp.local"), domains);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ignoreInvalidEntries() throws Exception {
|
||||
File f = buildFile("domain netty.local\n" +
|
||||
"nameserver nil\n" +
|
||||
"nameserver 127.0.0.3\n");
|
||||
UnixResolverDnsServerAddressStreamProvider p =
|
||||
new UnixResolverDnsServerAddressStreamProvider(f, null);
|
||||
|
||||
DnsServerAddressStream stream = p.nameServerAddressStream("somehost");
|
||||
assertEquals(1, stream.size());
|
||||
assertHostNameEquals("127.0.0.3", stream.next());
|
||||
}
|
||||
|
||||
private File buildFile(String contents) throws IOException {
|
||||
File f = folder.newFile();
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
|
Loading…
Reference in New Issue
Block a user