Skip to content

Commit 3934304

Browse files
committed
Add a fix and a test for DIRAPI-400
1 parent a7725ad commit 3934304

File tree

2 files changed

+11
-4
lines changed
  • ldap/model/src

2 files changed

+11
-4
lines changed

ldap/model/src/main/java/org/apache/directory/api/ldap/model/url/LdapUrl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ private int parseIPV6( char[] chars, int pos )
638638
// Search for the closing ']'
639639
int start = pos;
640640

641-
while ( !Chars.isCharASCII( chars, pos, ']' ) )
641+
while ( !Chars.isCharASCII( chars, pos, ']' ) && ( pos < chars.length ) )
642642
{
643643
pos++;
644644
}
@@ -699,7 +699,7 @@ private int parseIPvFuture( char[] chars, int pos )
699699
// Now, we should have at least one char in unreserved / sub-delims / ":"
700700
boolean valueFound = false;
701701

702-
while ( !Chars.isCharASCII( chars, pos, ']' ) )
702+
while ( !Chars.isCharASCII( chars, pos, ']' ) && ( pos < chars.length ) )
703703
{
704704
switch ( chars[pos] )
705705
{
@@ -901,7 +901,7 @@ private int parseDecOctet( char[] chars, int pos, int[] ipElem, int octetNb )
901901
boolean ipElemSeen = false;
902902
boolean hasHeadingZeroes = false;
903903

904-
while ( Chars.isDigit( chars, pos ) )
904+
while ( Chars.isDigit( chars, pos ) && ( pos < chars.length ) )
905905
{
906906
ipElemSeen = true;
907907

@@ -974,7 +974,7 @@ private int parsePort( char[] chars, int pos )
974974

975975
pos++;
976976

977-
while ( Chars.isDigit( chars, pos ) )
977+
while ( Chars.isDigit( chars, pos ) && ( pos < chars.length ) )
978978
{
979979
port = ( port * 10 ) + ( chars[pos] - '0' );
980980

ldap/model/src/test/java/org/apache/directory/api/ldap/model/url/LdapUrlTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,4 +1683,11 @@ public void testLdapURLExtensionWithRFC3986UnreservedChars() throws Exception
16831683
"ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~",
16841684
url2.toString() );
16851685
}
1686+
1687+
1688+
@Test
1689+
public void hangingLdapUrl()
1690+
{
1691+
assertThrows( LdapURLEncodingException.class, () -> new LdapUrl( "ldap://[1:2:ldap:///o" ) );
1692+
}
16861693
}

0 commit comments

Comments
 (0)