From 61d874af100f0e20ed34796fe61e5f9f76a6506f Mon Sep 17 00:00:00 2001
From: Kurt Zeilenga <kurt@openldap.org>
Date: Fri, 4 May 2001 21:15:09 +0000
Subject: [PATCH] reimplementation of sb_max_incoming

---
 include/lber.h               |  4 +++-
 include/ldap.h               |  1 +
 libraries/liblber/io.c       |  7 ++++++-
 libraries/liblber/lber-int.h |  1 +
 libraries/liblber/sockbuf.c  | 13 +++++++++++++
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/include/lber.h b/include/lber.h
index e89d500473..64ecb23e18 100644
--- a/include/lber.h
+++ b/include/lber.h
@@ -131,8 +131,10 @@ typedef struct lber_memory_fns {
 #define LBER_SB_OPT_DRAIN		10
 #define LBER_SB_OPT_NEEDS_READ		11
 #define LBER_SB_OPT_NEEDS_WRITE		12
+#define LBER_SB_OPT_GET_MAX_INCOMING 13
+#define LBER_SB_OPT_SET_MAX_INCOMING 14
 /* Largest option used by the library */
-#define LBER_SB_OPT_OPT_MAX		12
+#define LBER_SB_OPT_OPT_MAX		14
 
 /* LBER IO operations stacking levels */
 #define LBER_SBIOD_LEVEL_PROVIDER	10
diff --git a/include/ldap.h b/include/ldap.h
index 09f5789175..241ec138d1 100644
--- a/include/ldap.h
+++ b/include/ldap.h
@@ -285,6 +285,7 @@ typedef struct ldapcontrol {
 
 /* sasl methods */
 #define LDAP_SASL_SIMPLE		((char*)0)
+#define LDAP_SASL_NULL			("")
 
 
 /* authentication methods available */
diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c
index 71a2feb1e6..36e4331104 100644
--- a/libraries/liblber/io.c
+++ b/libraries/liblber/io.c
@@ -546,10 +546,15 @@ get_lenbyte:
 
 fill_buffer:	
 	/* now fill the buffer. */
-	if (ber->ber_len==0) {
+
+	/* make sure length is reasonable */
+	if ( ber->ber_len == 0 ||
+		( sb->sb_max_incoming && ber->ber_len > sb->sb_max_incoming ))
+	{
 		errno = ERANGE;
 		return LBER_DEFAULT;
 	}
+
 	if (ber->ber_buf==NULL) {
 		ber->ber_buf = (char *) LBER_MALLOC( ber->ber_len );
 		if (ber->ber_buf==NULL) {
diff --git a/libraries/liblber/lber-int.h b/libraries/liblber/lber-int.h
index 78cac6d0a0..bb2ade16fc 100644
--- a/libraries/liblber/lber-int.h
+++ b/libraries/liblber/lber-int.h
@@ -87,6 +87,7 @@ struct sockbuf {
 	ber_socket_t		sb_fd;
    	unsigned int		sb_trans_needs_read:1;
    	unsigned int		sb_trans_needs_write:1;
+	ber_len_t			sb_max_incoming;
 };
 
 #define SOCKBUF_VALID( sb )	( (sb)->sb_valid == LBER_VALID_SOCKBUF )
diff --git a/libraries/liblber/sockbuf.c b/libraries/liblber/sockbuf.c
index e16a76c6f9..b4d7c4194b 100644
--- a/libraries/liblber/sockbuf.c
+++ b/libraries/liblber/sockbuf.c
@@ -73,6 +73,7 @@ ber_sockbuf_ctrl( Sockbuf *sb, int opt, void *arg )
 	int			ret = 0;
 
 	assert( sb != NULL );
+	assert( SOCKBUF_VALID( sb ) );
 
 	switch ( opt ) {
 		case LBER_SB_OPT_HAS_IO:
@@ -124,6 +125,18 @@ ber_sockbuf_ctrl( Sockbuf *sb, int opt, void *arg )
 			ret = ( sb->sb_trans_needs_write ? 1 : 0 );
 			break;
 
+		case LBER_SB_OPT_GET_MAX_INCOMING:
+			if ( arg != NULL ) {
+				*((ber_len_t *)arg) = sb->sb_max_incoming;
+			}
+			ret = 1;
+			break;
+
+		case LBER_SB_OPT_SET_MAX_INCOMING:
+			sb->sb_max_incoming = *((ber_len_t *)arg);
+			ret = 1;
+			break;
+
 		default:
 			ret = sb->sb_iod->sbiod_io->sbi_ctrl( sb->sb_iod,
 				opt, arg );
-- 
GitLab