Blame SOURCES/rh1194226.patch

c2cb23
# HG changeset patch
c2cb23
# User omajid
c2cb23
# Date 1429811282 14400
c2cb23
#      Thu Apr 23 13:48:02 2015 -0400
c2cb23
# Node ID f0137fa5ba5298a73f14ae508463dc7e890a70a5
c2cb23
# Parent  c73cca6a510dd3f269c85263e18141c850a37fdb
c2cb23
8074761, PR2471: Empty optional parameters of LDAP query are not interpreted as empty
c2cb23
Reviewed-by: vinnie
c2cb23
Contributed-by: Stanislav Baiduzhyi <sbaiduzh@redhat.com>
c2cb23
c2cb23
diff -r c73cca6a510d -r f0137fa5ba52 src/share/classes/com/sun/jndi/ldap/LdapURL.java
c2cb23
--- openjdk/jdk/src/share/classes/com/sun/jndi/ldap/LdapURL.java	Wed Jan 07 00:02:43 2015 +0000
c2cb23
+++ openjdk/jdk/src/share/classes/com/sun/jndi/ldap/LdapURL.java	Thu Apr 23 13:48:02 2015 -0400
c2cb23
@@ -26,9 +26,6 @@
c2cb23
 package com.sun.jndi.ldap;
c2cb23
 
c2cb23
 import javax.naming.*;
c2cb23
-import javax.naming.directory.*;
c2cb23
-import javax.naming.spi.*;
c2cb23
-import java.net.URL;
c2cb23
 import java.net.MalformedURLException;
c2cb23
 import java.io.UnsupportedEncodingException;
c2cb23
 import java.util.StringTokenizer;
c2cb23
@@ -211,43 +208,52 @@
c2cb23
 
c2cb23
         // query begins with a '?' or is null
c2cb23
 
c2cb23
-        if (query == null) {
c2cb23
+        if (query == null || query.length() < 2) {
c2cb23
             return;
c2cb23
         }
c2cb23
 
c2cb23
-        int qmark2 = query.indexOf('?', 1);
c2cb23
+        int currentIndex = 1;
c2cb23
+        int nextQmark;
c2cb23
+        int endIndex;
c2cb23
 
c2cb23
-        if (qmark2 < 0) {
c2cb23
-            attributes = query.substring(1);
c2cb23
+        // attributes:
c2cb23
+        nextQmark = query.indexOf('?', currentIndex);
c2cb23
+        endIndex = nextQmark == -1 ? query.length() : nextQmark;
c2cb23
+        if (endIndex - currentIndex > 0) {
c2cb23
+            attributes = query.substring(currentIndex, endIndex);
c2cb23
+        }
c2cb23
+        currentIndex = endIndex + 1;
c2cb23
+        if (currentIndex >= query.length()) {
c2cb23
             return;
c2cb23
-        } else if (qmark2 != 1) {
c2cb23
-            attributes = query.substring(1, qmark2);
c2cb23
         }
c2cb23
 
c2cb23
-        int qmark3 = query.indexOf('?', qmark2 + 1);
c2cb23
-
c2cb23
-        if (qmark3 < 0) {
c2cb23
-            scope = query.substring(qmark2 + 1);
c2cb23
+        // scope:
c2cb23
+        nextQmark = query.indexOf('?', currentIndex);
c2cb23
+        endIndex = nextQmark == -1 ? query.length() : nextQmark;
c2cb23
+        if (endIndex - currentIndex > 0) {
c2cb23
+            scope = query.substring(currentIndex, endIndex);
c2cb23
+        }
c2cb23
+        currentIndex = endIndex + 1;
c2cb23
+        if (currentIndex >= query.length()) {
c2cb23
             return;
c2cb23
-        } else if (qmark3 != qmark2 + 1) {
c2cb23
-            scope = query.substring(qmark2 + 1, qmark3);
c2cb23
         }
c2cb23
 
c2cb23
-        int qmark4 = query.indexOf('?', qmark3 + 1);
c2cb23
+        // filter:
c2cb23
+        nextQmark = query.indexOf('?', currentIndex);
c2cb23
+        endIndex = nextQmark == -1 ? query.length() : nextQmark;
c2cb23
+        if (endIndex - currentIndex > 0) {
c2cb23
+            filter = query.substring(currentIndex, endIndex);
c2cb23
+            filter = UrlUtil.decode(filter, "UTF8");
c2cb23
+        }
c2cb23
+        currentIndex = endIndex + 1;
c2cb23
+        if (currentIndex >= query.length()) {
c2cb23
+            return;
c2cb23
+        }
c2cb23
 
c2cb23
-        if (qmark4 < 0) {
c2cb23
-            filter = query.substring(qmark3 + 1);
c2cb23
-        } else {
c2cb23
-            if (qmark4 != qmark3 + 1) {
c2cb23
-                filter = query.substring(qmark3 + 1, qmark4);
c2cb23
-            }
c2cb23
-            extensions = query.substring(qmark4 + 1);
c2cb23
-            if (extensions.length() > 0) {
c2cb23
-                extensions = UrlUtil.decode(extensions, "UTF8");
c2cb23
-            }
c2cb23
-        }
c2cb23
-        if (filter != null && filter.length() > 0) {
c2cb23
-            filter = UrlUtil.decode(filter, "UTF8");
c2cb23
+        // extensions:
c2cb23
+        if (query.length() - currentIndex > 0) {
c2cb23
+            extensions = query.substring(currentIndex);
c2cb23
+            extensions = UrlUtil.decode(extensions, "UTF8");
c2cb23
         }
c2cb23
     }
c2cb23
 
c2cb23
diff -r c73cca6a510d -r f0137fa5ba52 test/com/sun/jndi/ldap/LdapURLOptionalFields.java
c2cb23
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
c2cb23
+++ openjdk/jdk/test/com/sun/jndi/ldap/LdapURLOptionalFields.java	Thu Apr 23 13:48:02 2015 -0400
c2cb23
@@ -0,0 +1,62 @@
c2cb23
+/*
c2cb23
+ * Copyright (c) 2015, Red Hat, Inc.
c2cb23
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c2cb23
+ *
c2cb23
+ * This code is free software; you can redistribute it and/or modify it
c2cb23
+ * under the terms of the GNU General Public License version 2 only, as
c2cb23
+ * published by the Free Software Foundation.
c2cb23
+ *
c2cb23
+ * This code is distributed in the hope that it will be useful, but WITHOUT
c2cb23
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c2cb23
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c2cb23
+ * version 2 for more details (a copy is included in the LICENSE file that
c2cb23
+ * accompanied this code).
c2cb23
+ *
c2cb23
+ * You should have received a copy of the GNU General Public License version
c2cb23
+ * 2 along with this work; if not, write to the Free Software Foundation,
c2cb23
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c2cb23
+ *
c2cb23
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c2cb23
+ * or visit www.oracle.com if you need additional information or have any
c2cb23
+ * questions.
c2cb23
+ */
c2cb23
+
c2cb23
+/**
c2cb23
+ * @test
c2cb23
+ * @bug 8074761
c2cb23
+ * @summary RFC-2255 allows attribute, scope and filter to be empty.
c2cb23
+ */
c2cb23
+
c2cb23
+import com.sun.jndi.ldap.LdapURL;
c2cb23
+
c2cb23
+public class LdapURLOptionalFields {
c2cb23
+
c2cb23
+    private static final String[] TEST_URLS = {
c2cb23
+        "ldap://localhost:10389/ou=RefPeople,dc=example,dc=com",
c2cb23
+        "ldap://localhost:10389/ou=RefPeople,dc=example,dc=com?",
c2cb23
+        "ldap://localhost:10389/ou=RefPeople,dc=example,dc=com??",
c2cb23
+        "ldap://localhost:10389/ou=RefPeople,dc=example,dc=com???",
c2cb23
+        "ldap://localhost:10389/ou=RefPeople,dc=example,dc=com????"
c2cb23
+    };
c2cb23
+
c2cb23
+    public static void main(String[] args) throws Exception {
c2cb23
+        for (int i = 0; i < TEST_URLS.length; i++) {
c2cb23
+            String url = TEST_URLS[i];
c2cb23
+            checkEmptyAttributes(url);
c2cb23
+        }
c2cb23
+    }
c2cb23
+
c2cb23
+    private static void checkEmptyAttributes(String urlString) throws Exception {
c2cb23
+        LdapURL url = new LdapURL(urlString);
c2cb23
+        if (url.getAttributes() != null) {
c2cb23
+            throw new Exception("Expected null attributes for url: '" + urlString + "'");
c2cb23
+        }
c2cb23
+        if (url.getScope() != null) {
c2cb23
+            throw new Exception("Expected null scope for url: '" + urlString + "'");
c2cb23
+        }
c2cb23
+        if (url.getFilter() != null) {
c2cb23
+            throw new Exception("Expected null filter for url: '" + urlString + "'");
c2cb23
+        }
c2cb23
+    }
c2cb23
+
c2cb23
+}