changeset 10825:608656dfa6ab

Merge
author mfang
date Thu, 11 Jun 2015 10:16:58 -0700
parents 8601693ed09e 32f149f8fbc0
children 8fd9ac5eb0a4
files
diffstat 6 files changed, 110 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Wed Jun 10 14:22:42 2015 -0700
+++ b/.hgtags	Thu Jun 11 10:16:58 2015 -0700
@@ -417,3 +417,4 @@
 a006fa0a9e8f18dee6daf8984bd11625c4c4860c jdk8u60-b15
 6ed3821c212a93ffc6bfcc292ef7aca3b7165139 jdk8u60-b16
 c30db4c968f63dce1bf2f9df240fb75a8f27f922 jdk8u60-b17
+57336c319de8a141d0bcd04265ce36734fb51380 jdk8u60-b18
--- a/src/share/classes/sun/nio/cs/ext/HKSCS.java	Wed Jun 10 14:22:42 2015 -0700
+++ b/src/share/classes/sun/nio/cs/ext/HKSCS.java	Thu Jun 11 10:16:58 2015 -0700
@@ -377,7 +377,6 @@
                             dst[dp++] = repl[1];
                         continue;
                     }
-                    sp++;
                 }
                 if (bb > MAX_SINGLEBYTE) {        // DoubleByte
                     dst[dp++] = (byte)(bb >> 8);
--- a/src/solaris/native/java/net/Inet4AddressImpl.c	Wed Jun 10 14:22:42 2015 -0700
+++ b/src/solaris/native/java/net/Inet4AddressImpl.c	Thu Jun 11 10:16:58 2015 -0700
@@ -144,7 +144,7 @@
     jobjectArray ret = 0;
     int retLen = 0;
 
-    int error=0;
+    int getaddrinfo_error=0;
     struct addrinfo hints, *res, *resNew = NULL;
 
     if (!initializeInetClasses(env))
@@ -172,22 +172,23 @@
         return NULL;
     }
 
+    getaddrinfo_error = getaddrinfo(hostname, NULL, &hints, &res);
+
 #ifdef MACOSX
-    /* If we're looking up the local machine, bypass DNS lookups and get
-     * address from getifaddrs.
-     */
-    ret = lookupIfLocalhost(env, hostname, JNI_FALSE);
-    if (ret != NULL || (*env)->ExceptionCheck(env)) {
-        JNU_ReleaseStringPlatformChars(env, host, hostname);
-        return ret;
+    if (getaddrinfo_error) {
+        // If getaddrinfo fails try getifaddrs.
+        ret = lookupIfLocalhost(env, hostname, JNI_FALSE);
+        if (ret != NULL || (*env)->ExceptionCheck(env)) {
+            JNU_ReleaseStringPlatformChars(env, host, hostname);
+            return ret;
+        }
     }
 #endif
 
-    error = getaddrinfo(hostname, NULL, &hints, &res);
-
-    if (error) {
+    if (getaddrinfo_error) {
         /* report error */
-        ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
+        ThrowUnknownHostExceptionWithGaiError(
+            env, hostname, getaddrinfo_error);
         JNU_ReleaseStringPlatformChars(env, host, hostname);
         return NULL;
     } else {
--- a/src/solaris/native/java/net/Inet6AddressImpl.c	Wed Jun 10 14:22:42 2015 -0700
+++ b/src/solaris/native/java/net/Inet6AddressImpl.c	Thu Jun 11 10:16:58 2015 -0700
@@ -296,7 +296,7 @@
     jobjectArray ret = 0;
     int retLen = 0;
 
-    int error=0;
+    int getaddrinfo_error=0;
 #ifdef AF_INET6
     struct addrinfo hints, *res, *resNew = NULL;
 #endif /* AF_INET6 */
@@ -311,19 +311,6 @@
     hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
     CHECK_NULL_RETURN(hostname, NULL);
 
-#ifdef MACOSX
-    /*
-     * If we're looking up the local machine, attempt to get the address
-     * from getifaddrs. This ensures we get an IPv6 address for the local
-     * machine.
-     */
-    ret = lookupIfLocalhost(env, hostname, JNI_TRUE);
-    if (ret != NULL || (*env)->ExceptionCheck(env)) {
-        JNU_ReleaseStringPlatformChars(env, host, hostname);
-        return ret;
-    }
-#endif
-
 #ifdef AF_INET6
     /* Try once, with our static buffer. */
     memset(&hints, 0, sizeof(hints));
@@ -343,11 +330,27 @@
     }
 #endif
 
-    error = getaddrinfo(hostname, NULL, &hints, &res);
+    getaddrinfo_error = getaddrinfo(hostname, NULL, &hints, &res);
 
-    if (error) {
+#ifdef MACOSX
+    if (getaddrinfo_error) {
+        /*
+         * If getaddrinfo fails looking up the local machine, attempt to get the
+         * address from getifaddrs. This ensures we get an IPv6 address for the
+         * local machine.
+         */
+        ret = lookupIfLocalhost(env, hostname, JNI_TRUE);
+        if (ret != NULL || (*env)->ExceptionCheck(env)) {
+            JNU_ReleaseStringPlatformChars(env, host, hostname);
+            return ret;
+        }
+    }
+#endif
+
+    if (getaddrinfo_error) {
         /* report error */
-        ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
+        ThrowUnknownHostExceptionWithGaiError(
+            env, hostname, getaddrinfo_error);
         JNU_ReleaseStringPlatformChars(env, host, hostname);
         return NULL;
     } else {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/xml/jaxp/testng/parse/jdk7156085/UTF8ReaderBug.java	Thu Jun 11 10:16:58 2015 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2014 Google, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package parse.jdk7156085;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.helpers.DefaultHandler;
+import org.testng.annotations.Test;
+
+/**
+ * JDK-7156085: ArrayIndexOutOfBoundsException throws in UTF8Reader of SAXParser
+ * https://bugs.openjdk.java.net/browse/JDK-7156085
+ *
+ * XERCESJ-1257: buffer overflow in UTF8Reader for characters out of BMP
+ * https://issues.apache.org/jira/browse/XERCESJ-1257
+ */
+public class UTF8ReaderBug {
+    @Test
+    public void shouldAcceptSupplementaryCharacters() throws Throwable {
+        StringBuilder b = new StringBuilder("<xml>");
+        for(int i = 5; i < 8223; i++) {
+            b.append(' ');
+        }
+        // Add surrogate characters which overflow the buffer. This shows the need to place an
+        // overflow check at --
+        // com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:544)
+        b.append("\uD835\uDC37");
+        b.append("</xml>");
+        sendToParser(b.toString());
+    }
+
+    private static void sendToParser(String b) throws Throwable {
+        byte[] input = b.getBytes("UTF-8");
+        ByteArrayInputStream in = new ByteArrayInputStream(input);
+
+        SAXParserFactory  spf = SAXParserFactory.newInstance();
+        SAXParser p = spf.newSAXParser();
+        p.parse(new InputSource(in), new DefaultHandler());
+    }
+}
--- a/test/sun/nio/cs/TestStringCoding.java	Wed Jun 10 14:22:42 2015 -0700
+++ b/test/sun/nio/cs/TestStringCoding.java	Thu Jun 11 10:16:58 2015 -0700
@@ -22,7 +22,7 @@
  */
 
 /* @test
-   @bug 6636323 6636319 7040220 7096080 7183053
+   @bug 6636323 6636319 7040220 7096080 7183053 8080248
    @summary Test if StringCoding and NIO result have the same de/encoding result
  * @run main/othervm/timeout=2000 TestStringCoding
  */
@@ -199,6 +199,17 @@
             */
         }
 
+        //encode mappable surrogates for hkscs
+        if (cs.name().equals("Big5-HKSCS") || cs.name().equals("x-MS950-HKSCS")) {
+            String str = "ab\uD840\uDD0Ccd";
+            byte[] expected = new byte[] {(byte)'a', (byte)'b',
+                (byte)0x88, (byte)0x45, (byte)'c', (byte)'d' };
+            if (!Arrays.equals(str.getBytes(cs.name()), expected) ||
+                !Arrays.equals(str.getBytes(cs), expected)) {
+                throw new RuntimeException("encode(surrogates) failed  -> "
+                                           + cs.name());
+            }
+        }
     }
 
     static class PermissiveSecurityManger extends SecurityManager {