mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
17.50.2016 d6b66772a5c1ad1403e9cfb3f96ef6abfb13f0b9
OPENDJ-3020 Fix some AttributeDescription related NPEs

Code using an ASCIICharProp did not properly test for non-ascii characters.
Moreover, attribute options could end up referencing the whole list of options instead of its unique values.
2 files modified
24 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java 20 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java 4 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
@@ -853,7 +853,7 @@
                }
                cp = ASCIICharProp.valueOf(c);
                if (!cp.isKeyChar(allowMalformedNamesAndOptions)) {
                if (cp == null || !cp.isKeyChar(allowMalformedNamesAndOptions)) {
                    final LocalizableMessage message =
                            ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription,
                                    c, i);
@@ -873,7 +873,7 @@
                }
                cp = ASCIICharProp.valueOf(c);
                if (c != '.' && !cp.isDigit()) {
                if (cp == null || c != '.' && !cp.isDigit()) {
                    final LocalizableMessage message =
                            ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription,
                                    c, i);
@@ -934,7 +934,7 @@
            }
            cp = ASCIICharProp.valueOf(c);
            if (!cp.isKeyChar(allowMalformedNamesAndOptions)) {
            if (cp == null || !cp.isKeyChar(allowMalformedNamesAndOptions)) {
                final LocalizableMessage message =
                        ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription, c, i);
                throw new LocalizedIllegalArgumentException(message);
@@ -999,7 +999,7 @@
                }
                cp = ASCIICharProp.valueOf(c);
                if (!cp.isKeyChar(allowMalformedNamesAndOptions)) {
                if (cp == null || !cp.isKeyChar(allowMalformedNamesAndOptions)) {
                    final LocalizableMessage message =
                            ERR_ATTRIBUTE_DESCRIPTION_ILLEGAL_CHARACTER.get(attributeDescription,
                                    c, i);
@@ -1037,13 +1037,17 @@
                i = skipTrailingWhiteSpace(attributeDescription, i + 1, length);
            }
            options.add(option);
            normalizedOptions.add(normalizedOption);
            if (normalizedOptions.add(normalizedOption)) {
                options.add(option);
            }
        }
        return new AttributeDescription(attributeDescription, oid, attributeType,
                new MultiOptionImpl(options.toArray(new String[options.size()]),
                                    normalizedOptions.toArray(new String[normalizedOptions.size()])));
                normalizedOptions.size() > 1
                    ? new MultiOptionImpl(options.toArray(new String[options.size()]),
                            normalizedOptions.toArray(new String[normalizedOptions.size()]))
                    : new SingleOptionImpl(options.get(0), normalizedOptions.first())
        );
    }
    private final String attributeDescription;
opendj-core/src/test/java/org/forgerock/opendj/ldap/AttributeDescriptionTestCase.java
@@ -82,6 +82,8 @@
            { "cn;xxx;yyy", "cn;xxx", 1, true, false },
            { "cn;xxx;yyy", "cn;xxx;yyy", 0, true, true },
            { "cn;xxx;yyy", "cn;yyy;xxx", 0, true, true },
            { "cn;a;a;a;a", "cn;a", 0, false, false},
            { "cn;a;b;a", "cn;a;b", 0, false, false},
            { "cn", "cn;xxx;yyy", -1, false, true },
            { "cn;yyy", "cn;xxx;yyy", -1, false, true },
@@ -167,6 +169,8 @@
            { "cn;xxx;yyy;zzz", "cn", new String[] { "xxx", "yyy", "zzz" }, false },
            { "cn;zzz;YYY;xxx", "cn", new String[] { "zzz", "YYY", "xxx" }, false },
            { "CN;zzz;YYY;xxx", "CN", new String[] { "zzz", "YYY", "xxx" }, false },
            { "cn;a;a;b", "cn", new String[] { "a", "b" }, false},
            { "cn;a;a;a;a", "cn", new String[] { "a" }, false},
        };
        // @formatter:on
    }