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/07/26 16:19:04 UTC
(directory-server) branch master updated: Fix for DIRSERVER-2406
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-server.git
The following commit(s) were added to refs/heads/master by this push:
new 398dc28a60 Fix for DIRSERVER-2406
398dc28a60 is described below
commit 398dc28a60a4d0b31a7c088e56819109ff66b5d0
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Fri Jul 26 18:19:00 2024 +0200
Fix for DIRSERVER-2406
---
.../server/dhcp/io/DhcpMessageDecoder.java | 66 +++++++++++++---------
1 file changed, 40 insertions(+), 26 deletions(-)
diff --git a/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java b/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java
index 19507c8469..ff80e0b63b 100644
--- a/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java
+++ b/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java
@@ -24,6 +24,7 @@ package org.apache.directory.server.dhcp.io;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.Arrays;
@@ -52,32 +53,39 @@ public class DhcpMessageDecoder
*/
public DhcpMessage decode( ByteBuffer buffer ) throws DhcpException
{
- byte op = buffer.get();
-
- short htype = ( short ) ( buffer.get() & 0xff );
- short hlen = ( short ) ( buffer.get() & 0xff );
- short hops = ( short ) ( buffer.get() & 0xff );
- int xid = buffer.getInt();
- int secs = buffer.getShort() & 0xffff;
- short flags = buffer.getShort();
-
- InetAddress ciaddr = decodeAddress( buffer );
- InetAddress yiaddr = decodeAddress( buffer );
- InetAddress siaddr = decodeAddress( buffer );
- InetAddress giaddr = decodeAddress( buffer );
-
- byte[] chaddr = decodeBytes( buffer, 16 );
-
- String sname = decodeString( buffer, 64 );
- String file = decodeString( buffer, 128 );
-
- OptionsField options = decodeOptions( buffer );
-
- // message type option: may be null if option isn't set (BOOTP)
- DhcpMessageType mto = ( DhcpMessageType ) options.get( DhcpMessageType.class );
-
- return new DhcpMessage( null != mto ? mto.getType() : null, op, new HardwareAddress( htype, hlen, chaddr ),
- hops, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, sname, file, options );
+ try
+ {
+ byte op = buffer.get();
+
+ short htype = ( short ) ( buffer.get() & 0xff );
+ short hlen = ( short ) ( buffer.get() & 0xff );
+ short hops = ( short ) ( buffer.get() & 0xff );
+ int xid = buffer.getInt();
+ int secs = buffer.getShort() & 0xffff;
+ short flags = buffer.getShort();
+
+ InetAddress ciaddr = decodeAddress( buffer );
+ InetAddress yiaddr = decodeAddress( buffer );
+ InetAddress siaddr = decodeAddress( buffer );
+ InetAddress giaddr = decodeAddress( buffer );
+
+ byte[] chaddr = decodeBytes( buffer, 16 );
+
+ String sname = decodeString( buffer, 64 );
+ String file = decodeString( buffer, 128 );
+
+ OptionsField options = decodeOptions( buffer );
+
+ // message type option: may be null if option isn't set (BOOTP)
+ DhcpMessageType mto = ( DhcpMessageType ) options.get( DhcpMessageType.class );
+
+ return new DhcpMessage( null != mto ? mto.getType() : null, op, new HardwareAddress( htype, hlen, chaddr ),
+ hops, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, sname, file, options );
+ }
+ catch ( BufferUnderflowException bue )
+ {
+ throw new DhcpException( I18n.err( I18n.ERR_643, bue.toString() ) );
+ }
}
@@ -180,6 +188,12 @@ public class DhcpMessageDecoder
}
length = message.get();
+
+ if ( length < 0 )
+ {
+ throw new DhcpException( I18n.err( I18n.ERR_644 ) );
+ }
+
value = new byte[length];
message.get( value );