You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2024/06/03 03:09:21 UTC

(directory-ldap-api) branch master updated: Fix for DIRAPI-403

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new edcb3deca Fix for DIRAPI-403
edcb3deca is described below

commit edcb3decafa6f0d98894d31138de2ca68351d681
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Mon Jun 3 05:08:39 2024 +0200

    Fix for DIRAPI-403
---
 .../apache/directory/api/asn1/ber/Asn1Decoder.java   |  6 ++++++
 .../ldap/client/api/LdapNetworkConnection.java       | 10 ++++++----
 .../directory/api/ldap/codec/LdapDecoderTest.java    | 20 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/Asn1Decoder.java b/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/Asn1Decoder.java
index 2a0a90884..4747c2672 100644
--- a/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/Asn1Decoder.java
+++ b/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/Asn1Decoder.java
@@ -355,6 +355,12 @@ public final class Asn1Decoder implements TLVBerDecoderMBean
         }
 
         int length = tlv.getLength();
+        
+        // Check we arent above the MAX PDU
+        if ( length > container.getMaxPDUSize() )
+        {
+            throw new DecoderException( I18n.err( I18n.ERR_01007_PDU_SIZE_TOO_LONG, length, container.getMaxPDUSize() ) );
+        }
 
         // We will check the length here. What we must control is
         // that the enclosing constructed TLV expected length is not
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
index bd7fd07c5..448834e05 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -541,16 +541,18 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
     {
         // Use only one thread inside the connector
         connector = new NioSocketConnector( 1 );
+        SocketSessionConfig socketSessionConfig = ( ( SocketSessionConfig ) connector.getSessionConfig() );
         
-        if ( socketSessionConfig != null )
+        if ( this.socketSessionConfig != null )
         {
-            ( ( SocketSessionConfig ) connector.getSessionConfig() ).setAll( socketSessionConfig );
+            socketSessionConfig.setAll( this.socketSessionConfig );
         }
         else
         {
-            ( ( SocketSessionConfig ) connector.getSessionConfig() ).setReuseAddress( true );
+            socketSessionConfig.setReuseAddress( true );
+            socketSessionConfig.setTcpNoDelay( true );
         }
-
+        
         // Add the codec to the chain
         connector.getFilterChain().addLast( LDAP_CODEC_FILTER_KEY, ldapProtocolFilter );
 
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapDecoderTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapDecoderTest.java
index e8b7aa919..cf030c9b3 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapDecoderTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/LdapDecoderTest.java
@@ -518,4 +518,24 @@ public class LdapDecoderTest extends AbstractCodecServiceTest
         // Check the decoded length
         assertEquals( 384, container.getCurrentTLV().getLength() );
     }
+
+
+    /**
+     * Test that a big PDU is not accepted when the MaxPDU size is set
+     */
+    @Test
+    public void testDecodeOOM() throws DecoderException
+    {
+        byte[] input = java.util.Base64.getDecoder().decode( "QIR+fnR+yvD/" );
+        ByteBuffer stream = ByteBuffer.allocate(input.length);
+        stream.put(input);
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        LdapMessageContainer<Message> container = new LdapMessageContainer<>( codec );
+        container.setMaxPDUSize( 1024 );
+
+        // Decode a PDU which is going to be bigger than the MAX PDU size: should throw an exception
+        assertThrows( DecoderException.class, () -> { Asn1Decoder.decode( stream, container ); } );
+    }
 }