1 |
|
2 |
# HG changeset patch |
3 |
# User robm |
4 |
# Date 1430151427 -3600 |
5 |
# Node ID b02550d62bdbaf61a258628b47acc3fc7982d7e5 |
6 |
# Parent 70aaa6da3101e6c2feeabce3b36d50624ed918ad |
7 |
6991580: IPv6 Nameservers in resolv.conf throws NumberFormatException |
8 |
Reviewed-by: michaelm, andrew, alanb, rriggs |
9 |
Contributed-by: sgehwolf@redhat.com |
10 |
|
11 |
diff -r 70aaa6da3101 -r b02550d62bdb src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java |
12 |
--- jdk8/jdk/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java Sun Apr 19 10:31:06 2015 +0300 |
13 |
+++ jdk8/jdk/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java Mon Apr 27 17:17:07 2015 +0100 |
14 |
@@ -85,6 +85,15 @@ |
15 |
if (val.charAt(0) == '#' || val.charAt(0) == ';') { |
16 |
break; |
17 |
} |
18 |
+ if ("nameserver".equals(keyword)) { |
19 |
+ if (val.indexOf(':') >= 0 && |
20 |
+ val.indexOf('.') < 0 && // skip for IPv4 literals with port |
21 |
+ val.indexOf('[') < 0 && |
22 |
+ val.indexOf(']') < 0 ) { |
23 |
+ // IPv6 literal, in non-BSD-style. |
24 |
+ val = "[" + val + "]"; |
25 |
+ } |
26 |
+ } |
27 |
ll.add(val); |
28 |
if (--maxvalues == 0) { |
29 |
break; |
30 |
diff -r 70aaa6da3101 -r b02550d62bdb test/com/sun/jndi/dns/IPv6NameserverPlatformParsingTest.java |
31 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
32 |
+++ jdk8/jdk/test/com/sun/jndi/dns/IPv6NameserverPlatformParsingTest.java Mon Apr 27 17:17:07 2015 +0100 |
33 |
@@ -0,0 +1,104 @@ |
34 |
+/* |
35 |
+ * Copyright (c) 2015, Red Hat, Inc. |
36 |
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
37 |
+ * |
38 |
+ * This code is free software; you can redistribute it and/or modify it |
39 |
+ * under the terms of the GNU General Public License version 2 only, as |
40 |
+ * published by the Free Software Foundation. |
41 |
+ * |
42 |
+ * This code is distributed in the hope that it will be useful, but WITHOUT |
43 |
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
44 |
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
45 |
+ * version 2 for more details (a copy is included in the LICENSE file that |
46 |
+ * accompanied this code). |
47 |
+ * |
48 |
+ * You should have received a copy of the GNU General Public License version |
49 |
+ * 2 along with this work; if not, write to the Free Software Foundation, |
50 |
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
51 |
+ * |
52 |
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
53 |
+ * or visit www.oracle.com if you need additional information or have any |
54 |
+ * questions. |
55 |
+ */ |
56 |
+ |
57 |
+import java.lang.reflect.Field; |
58 |
+import java.util.Hashtable; |
59 |
+ |
60 |
+import javax.naming.Context; |
61 |
+import javax.naming.NamingException; |
62 |
+import javax.naming.spi.NamingManager; |
63 |
+ |
64 |
+import com.sun.jndi.dns.DnsContext; |
65 |
+ |
66 |
+/** |
67 |
+ * @test |
68 |
+ * @bug 6991580 |
69 |
+ * @summary IPv6 Nameservers in resolv.conf throws NumberFormatException |
70 |
+ * @run main/manual IPv6NameserverPlatformParsingTest |
71 |
+ * |
72 |
+ * In order to run this test be sure to place, for example, the following |
73 |
+ * snippet into your platform's {@code /etc/resolv.conf}: |
74 |
+ * <pre> |
75 |
+ * nameserver 127.0.0.1 |
76 |
+ * nameserver 2001:4860:4860::8888 |
77 |
+ * nameserver [::1]:5353 |
78 |
+ * nameserver 127.0.0.1:5353 |
79 |
+ * </pre> |
80 |
+ * |
81 |
+ * Then, run this test as manual jtreg test. |
82 |
+ * |
83 |
+ * @author Severin Gehwolf |
84 |
+ * |
85 |
+ */ |
86 |
+public class IPv6NameserverPlatformParsingTest { |
87 |
+ |
88 |
+ private static boolean foundIPv6 = false; |
89 |
+ |
90 |
+ public static void main(String[] args) { |
91 |
+ Hashtable<String, String> env = new Hashtable<>(); |
92 |
+ env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.dns.DnsContextFactory.class.getName()); |
93 |
+ |
94 |
+ String[] servers; |
95 |
+ try { |
96 |
+ Context ctx = NamingManager.getInitialContext(env); |
97 |
+ if (!com.sun.jndi.dns.DnsContextFactory.platformServersAvailable()) { |
98 |
+ throw new RuntimeException("FAIL: no platform servers available, test does not make sense"); |
99 |
+ } |
100 |
+ DnsContext context = (DnsContext)ctx; |
101 |
+ servers = getServersFromContext(context); |
102 |
+ } catch (NamingException e) { |
103 |
+ throw new RuntimeException(e); |
104 |
+ } |
105 |
+ for (String server: servers) { |
106 |
+ System.out.println("DEBUG: 'nameserver = " + server + "'"); |
107 |
+ if (server.indexOf(':') >= 0 && server.indexOf('.') < 0) { |
108 |
+ System.out.println("DEBUG: ==> Found IPv6 address in servers list: " + server); |
109 |
+ foundIPv6 = true; |
110 |
+ } |
111 |
+ } |
112 |
+ try { |
113 |
+ new com.sun.jndi.dns.DnsClient(servers, 100, 1); |
114 |
+ } catch (NumberFormatException e) { |
115 |
+ throw new RuntimeException("FAIL: Tried to parse non-[]-encapsulated IPv6 address.", e); |
116 |
+ } catch (Exception e) { |
117 |
+ throw new RuntimeException("ERROR: Something unexpected happened."); |
118 |
+ } |
119 |
+ if (!foundIPv6) { |
120 |
+ // This is a manual test, since it requires changing /etc/resolv.conf on Linux/Unix |
121 |
+ // platforms. See comment as to how to run this test. |
122 |
+ throw new RuntimeException("ERROR: No IPv6 address returned from platform."); |
123 |
+ } |
124 |
+ System.out.println("PASS: Found IPv6 address and DnsClient parsed it correctly."); |
125 |
+ } |
126 |
+ |
127 |
+ private static String[] getServersFromContext(DnsContext context) { |
128 |
+ try { |
129 |
+ Field serversField = DnsContext.class.getDeclaredField("servers"); |
130 |
+ serversField.setAccessible(true); |
131 |
+ return (String[])serversField.get(context); |
132 |
+ } catch (Exception e) { |
133 |
+ throw new RuntimeException(e); |
134 |
+ } |
135 |
+ } |
136 |
+ |
137 |
+} |
138 |
|