changeset 11307:ee47a5aac84e

8055045: StringIndexOutOfBoundsException while reading krb5.conf Reviewed-by: mullan
author weijun
date Mon, 26 Jan 2015 09:29:29 +0800
parents ebb2eb7f1aec
children 12c3328b687e
files src/java.security.jgss/share/classes/sun/security/krb5/Config.java test/sun/security/krb5/config/ParseConfig.java test/sun/security/krb5/config/krb5.conf
diffstat 3 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.security.jgss/share/classes/sun/security/krb5/Config.java	Sat Jan 24 23:23:25 2015 -0800
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/Config.java	Mon Jan 26 09:29:29 2015 +0800
@@ -913,9 +913,9 @@
 
     private static String unquote(String s) {
         s = s.trim();
-        if (s.isEmpty()) return s;
-        if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"' ||
-                s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\'') {
+        if (s.length() >= 2 &&
+                ((s.charAt(0) == '"' && s.charAt(s.length()-1) == '"') ||
+                 (s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\''))) {
             s = s.substring(1, s.length()-1).trim();
         }
         return s;
--- a/test/sun/security/krb5/config/ParseConfig.java	Sat Jan 24 23:23:25 2015 -0800
+++ b/test/sun/security/krb5/config/ParseConfig.java	Mon Jan 26 09:29:29 2015 +0800
@@ -22,7 +22,7 @@
  */
 /*
  * @test
- * @bug 6319046
+ * @bug 6319046 8055045
  * @compile -XDignore.symbol.file ParseConfig.java
  * @run main/othervm ParseConfig
  * @summary Problem with parsing krb5.conf
@@ -32,7 +32,8 @@
 
 public class ParseConfig {
     public static void main(String[] args) throws Exception {
-        System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") +"/krb5.conf");
+        System.setProperty("java.security.krb5.conf",
+                System.getProperty("test.src", ".") + "/krb5.conf");
         Config config = Config.getInstance();
         config.listTable();
 
@@ -44,5 +45,11 @@
                         expected + "\"");
             }
         }
+
+        // JDK-8055045: IOOBE when reading an empty value
+        config.get("empty1", "NOVAL.COM");
+        config.get("empty2", "NOVAL.COM");
+        config.get("quote1", "NOVAL.COM");
+        config.get("quote2", "NOVAL.COM");
     }
 }
--- a/test/sun/security/krb5/config/krb5.conf	Sat Jan 24 23:23:25 2015 -0800
+++ b/test/sun/security/krb5/config/krb5.conf	Mon Jan 26 09:29:29 2015 +0800
@@ -27,3 +27,9 @@
 	}
    }
 
+   NOVAL.COM = {
+        empty1 =
+        empty2 =.
+        quote1 = "
+        quote2 = '
+   }