Commit ecccaf84 authored by Quanah Gibson-Mount's avatar Quanah Gibson-Mount
Browse files

ITS#6215

parent afc60dcb
OpenLDAP 2.4 Change Log
OpenLDAP 2.4.18 Engineering
Fixed liblber speed and other problems (ITS#6215)
Fixed libldap tls_check_hostname for OpenSSL and MozNSS (ITS#6239)
Fixed slapd dncachesize behavior to unlimited by default (ITS#6222)
Fixed slapd incorrectly applying writetimeout when not set (ITS#6220)
......
......@@ -165,7 +165,6 @@ LBER_V( char ) ber_pvt_opt_on;
typedef struct berelement BerElement;
typedef struct sockbuf Sockbuf;
typedef struct seqorset Seqorset;
typedef struct sockbuf_io Sockbuf_IO;
......@@ -229,10 +228,6 @@ LBER_F( void )
ber_dump LDAP_P((
BerElement *ber, int inout ));
LBER_F( void )
ber_sos_dump LDAP_P((
Seqorset *sos ));
/*
* in decode.c:
*/
......@@ -434,7 +429,7 @@ ber_write LDAP_P((
BerElement *ber,
LDAP_CONST char *buf,
ber_len_t len,
int nosos ));
int zero )); /* nonzero is unsupported from OpenLDAP 2.4.18 */
LBER_F( void )
ber_free LDAP_P((
......
......@@ -276,47 +276,21 @@ ber_dump(
ber_bprint( ber->ber_ptr, len );
}
typedef struct seqorset Seqorset;
/* Exists for binary compatibility with OpenLDAP 2.4.17-- */
int
ber_log_sos_dump(
int errlvl,
int loglvl,
Seqorset *sos )
{
assert( sos != NULL );
if ( !ber_log_check( errlvl, loglvl )) {
return 0;
}
ber_sos_dump( sos );
return 1;
return 0;
}
/* Exists for binary compatibility with OpenLDAP 2.4.17-- */
void
ber_sos_dump(
Seqorset *sos )
{
char buf[132];
assert( sos != NULL );
(*ber_pvt_log_print)( "*** sos dump ***\n" );
while ( sos != NULL ) {
sprintf( buf, "ber_sos_dump: clen %ld first %p ptr %p\n",
(long) sos->sos_clen,
sos->sos_first,
sos->sos_ptr );
(*ber_pvt_log_print)( buf );
sprintf( buf, " current len %ld contents:\n",
(long) (sos->sos_ptr - sos->sos_first) );
(*ber_pvt_log_print)( buf );
ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
sos = sos->sos_next;
}
(*ber_pvt_log_print)( "*** end dump ***\n" );
}
......@@ -33,17 +33,12 @@
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/stdarg.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "lber-int.h"
static ber_len_t ber_getnint LDAP_P((
BerElement *ber,
ber_int_t *num,
ber_len_t len ));
/* out->bv_len should be the buffer size on input */
int
......@@ -97,7 +92,6 @@ ber_get_tag( BerElement *ber )
{
unsigned char xbyte;
ber_tag_t tag;
unsigned int i;
assert( ber != NULL );
assert( LBER_VALID( ber ) );
......@@ -117,50 +111,44 @@ ber_get_tag( BerElement *ber )
return tag;
}
for ( i = 1; i < sizeof(ber_tag_t); i++ ) {
do {
if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
return LBER_DEFAULT;
break;
}
tag <<= 8;
tag |= 0x00ffUL & (ber_tag_t) xbyte;
if ( ! (xbyte & LBER_MORE_TAG_MASK) ) {
break;
return tag;
}
}
/* tag too big! */
if ( i == sizeof(ber_tag_t) ) {
return LBER_DEFAULT;
}
} while ( tag <= (ber_tag_t)-1 / 256 );
return tag;
return LBER_DEFAULT; /* error or tag too big */
}
ber_tag_t
ber_skip_tag( BerElement *ber, ber_len_t *len )
ber_skip_tag( BerElement *ber, ber_len_t *lenp )
{
ber_tag_t tag;
ber_len_t len;
unsigned i, noctets;
unsigned char lc;
ber_len_t i, noctets;
unsigned char netlen[sizeof(ber_len_t)];
assert( ber != NULL );
assert( len != NULL );
assert( LBER_VALID( ber ) );
assert( lenp != NULL );
/*
* Any ber element looks like this: tag length contents.
* Assuming everything's ok, we return the tag byte (we
* can assume a single byte), and return the length in len.
* can assume a single byte), and return the length in lenp.
*
* Assumptions:
* 1) definite lengths
* 2) primitive encodings used whenever possible
*/
*len = 0;
*lenp = 0;
/*
* First, we read the tag.
......@@ -171,20 +159,23 @@ ber_skip_tag( BerElement *ber, ber_len_t *len )
}
/*
* Next, read the length. The first byte contains the length of
* the length. If bit 8 is set, the length is the long form,
* otherwise it's the short form. We don't allow a length that's
* greater than what we can hold in a ber_len_t.
* Next, read the length. The first octet determines the length
* of the length. If bit 8 is 0, the length is the short form,
* otherwise if the octet != 0x80 it's the long form, otherwise
* the ber element has the unsupported indefinite-length format.
* Lengths that do not fit in a ber_len_t are not accepted.
*/
if ( ber_read( ber, (char *) &lc, 1 ) != 1 ) {
return LBER_DEFAULT;
}
len = lc;
if ( lc & 0x80U ) {
noctets = (lc & 0x7fU);
if ( noctets > sizeof(ber_len_t) ) {
if ( noctets - 1U > sizeof(ber_len_t) - 1U ) {
/* Indefinite-length or too long length */
return LBER_DEFAULT;
}
......@@ -192,17 +183,17 @@ ber_skip_tag( BerElement *ber, ber_len_t *len )
return LBER_DEFAULT;
}
for( i = 0; i < noctets; i++ ) {
*len <<= 8;
*len |= netlen[i];
len = netlen[0];
for( i = 1; i < noctets; i++ ) {
len <<= 8;
len |= netlen[i];
}
} else {
*len = lc;
}
*lenp = len;
/* BER element should have enough data left */
if( *len > (ber_len_t) ber_pvt_ber_remaining( ber ) ) {
if( len > (ber_len_t) ber_pvt_ber_remaining( ber ) ) {
return LBER_DEFAULT;
}
ber->ber_tag = *(unsigned char *)ber->ber_ptr;
......@@ -232,41 +223,40 @@ ber_peek_tag(
return tag;
}
static ber_len_t
ber_getnint(
ber_tag_t
ber_get_int(
BerElement *ber,
ber_int_t *num,
ber_len_t len )
ber_int_t *num )
{
ber_tag_t tag;
ber_len_t len;
unsigned char buf[sizeof(ber_int_t)];
assert( ber != NULL );
assert( num != NULL );
assert( LBER_VALID( ber ) );
/*
* The tag and length have already been stripped off. We should
* be sitting right before len bytes of 2's complement integer,
* ready to be read straight into an int. We may have to sign
* extend after we read it in.
*/
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
if ( len > sizeof(ber_int_t) ) {
return -1;
return LBER_DEFAULT;
}
/* read into the low-order bytes of our buffer */
if ( (ber_len_t) ber_read( ber, (char *) buf, len ) != len ) {
return -1;
return LBER_DEFAULT;
}
/* parse two's complement integer */
if( len ) {
/* sign extend if necessary */
ber_len_t i;
ber_int_t netnum = 0x80 & buf[0] ? -1 : 0;
ber_int_t netnum = buf[0] & 0xff;
/* sign extend */
netnum -= (netnum & 0x80) << 1;
/* shift in the bytes */
for( i=0 ; i<len; i++ ) {
for( i = 1; i < len; i++ ) {
netnum = (netnum << 8 ) | buf[i];
}
......@@ -275,30 +265,9 @@ ber_getnint(
} else {
*num = 0;
}
ber->ber_tag = *(unsigned char *)ber->ber_ptr;
return len;
}
ber_tag_t
ber_get_int(
BerElement *ber,
ber_int_t *num )
{
ber_tag_t tag;
ber_len_t len;
assert( ber != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
ber->ber_tag = *(unsigned char *)ber->ber_ptr;
if ( ber_getnint( ber, num, len ) != len ) {
return LBER_DEFAULT;
}
return tag;
}
......@@ -319,9 +288,6 @@ ber_get_stringb(
ber_len_t datalen;
ber_tag_t tag;
assert( ber != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
......@@ -445,7 +411,7 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
case BvVec:
bvp = ber_memalloc_x( sizeof( struct berval ), b->ber->ber_memctx);
if ( !bvp ) {
LBER_FREE(bv.bv_val);
ber_memfree_x( bv.bv_val, b->ber->ber_memctx );
goto nomem;
}
(*b->res.bv)[n] = bvp;
......@@ -463,21 +429,21 @@ nomem:
for (--n; n>=0; n--) {
switch(b->choice) {
case ChArray:
LBER_FREE((*b->res.c)[n]);
ber_memfree_x((*b->res.c)[n], b->ber->ber_memctx);
break;
case BvArray:
LBER_FREE((*b->res.ba)[n].bv_val);
ber_memfree_x((*b->res.ba)[n].bv_val, b->ber->ber_memctx);
break;
case BvVec:
LBER_FREE((*b->res.bv)[n]->bv_val);
LBER_FREE((*b->res.bv)[n]);
ber_memfree_x((*b->res.bv)[n]->bv_val, b->ber->ber_memctx);
ber_memfree_x((*b->res.bv)[n], b->ber->ber_memctx);
break;
default:
break;
}
}
}
LBER_FREE(*b->res.c);
ber_memfree_x(*b->res.c, b->ber->ber_memctx);
*b->res.c = NULL;
return LBER_DEFAULT;
}
......@@ -487,18 +453,12 @@ ber_get_stringbv( BerElement *ber, struct berval *bv, int option )
{
ber_tag_t tag;
assert( ber != NULL );
assert( bv != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &bv->bv_len )) == LBER_DEFAULT ) {
tag = ber_skip_tag( ber, &bv->bv_len );
if ( tag == LBER_DEFAULT ) {
bv->bv_val = NULL;
return LBER_DEFAULT;
}
if ( (ber_len_t) ber_pvt_ber_remaining( ber ) < bv->bv_len ) {
return LBER_DEFAULT;
return tag;
}
if ( option & LBER_BV_ALLOC ) {
......@@ -511,7 +471,7 @@ ber_get_stringbv( BerElement *ber, struct berval *bv, int option )
if ( bv->bv_len > 0 && (ber_len_t) ber_read( ber, bv->bv_val,
bv->bv_len ) != bv->bv_len )
{
LBER_FREE( bv->bv_val );
ber_memfree_x( bv->bv_val, ber->ber_memctx );
bv->bv_val = NULL;
return LBER_DEFAULT;
}
......@@ -531,23 +491,11 @@ ber_get_stringbv_null( BerElement *ber, struct berval *bv, int option )
{
ber_tag_t tag;
assert( ber != NULL );
assert( bv != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &bv->bv_len )) == LBER_DEFAULT ) {
tag = ber_skip_tag( ber, &bv->bv_len );
if ( tag == LBER_DEFAULT || bv->bv_len == 0 ) {
bv->bv_val = NULL;
return LBER_DEFAULT;
}
if ( (ber_len_t) ber_pvt_ber_remaining( ber ) < bv->bv_len ) {
return LBER_DEFAULT;
}
if ( bv->bv_len == 0 ) {
bv->bv_val = NULL;
ber->ber_tag = *(unsigned char *)ber->ber_ptr;
return tag;
}
......@@ -561,7 +509,7 @@ ber_get_stringbv_null( BerElement *ber, struct berval *bv, int option )
if ( bv->bv_len > 0 && (ber_len_t) ber_read( ber, bv->bv_val,
bv->bv_len ) != bv->bv_len )
{
LBER_FREE( bv->bv_val );
ber_memfree_x( bv->bv_val, ber->ber_memctx );
bv->bv_val = NULL;
return LBER_DEFAULT;
}
......@@ -620,7 +568,7 @@ ber_get_stringal( BerElement *ber, struct berval **bv )
tag = ber_get_stringbv( ber, *bv, LBER_BV_ALLOC );
if ( tag == LBER_DEFAULT ) {
LBER_FREE( *bv );
ber_memfree_x( *bv, ber->ber_memctx );
*bv = NULL;
}
return tag;
......@@ -636,31 +584,30 @@ ber_get_bitstringa(
ber_tag_t tag;
unsigned char unusedbits;
assert( ber != NULL );
assert( buf != NULL );
assert( blen != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
return LBER_DEFAULT;
goto fail;
}
--datalen;
*buf = (char *) ber_memalloc_x( datalen, ber->ber_memctx );
if ( *buf == NULL ) {
return LBER_DEFAULT;
if ( --datalen > (ber_len_t)-1 / 8 ) {
goto fail;
}
if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) {
LBER_FREE( buf );
*buf = NULL;
goto fail;
}
if ( unusedbits > 7 ) {
goto fail;
}
*buf = (char *) ber_memalloc_x( datalen, ber->ber_memctx );
if ( *buf == NULL ) {
return LBER_DEFAULT;
}
if ( (ber_len_t) ber_read( ber, *buf, datalen ) != datalen ) {
LBER_FREE( buf );
ber_memfree_x( buf, ber->ber_memctx );
*buf = NULL;
return LBER_DEFAULT;
}
......@@ -668,27 +615,19 @@ ber_get_bitstringa(
*blen = datalen * 8 - unusedbits;
return tag;
fail:
*buf = NULL;
return LBER_DEFAULT;
}
ber_tag_t
ber_get_null( BerElement *ber )
{
ber_len_t len;
ber_tag_t tag;
assert( ber != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
ber_tag_t tag = ber_skip_tag( ber, &len );
if ( len != 0 ) {
return LBER_DEFAULT;
}
ber->ber_tag = *(unsigned char *)ber->ber_ptr;
return( tag );
return( len == 0 ? tag : LBER_DEFAULT );
}
ber_tag_t
......@@ -696,18 +635,7 @@ ber_get_boolean(
BerElement *ber,
ber_int_t *boolval )
{
ber_int_t longbool;
ber_tag_t rc;
assert( ber != NULL );
assert( boolval != NULL );
assert( LBER_VALID( ber ) );
rc = ber_get_int( ber, &longbool );
*boolval = longbool;
return rc;
return ber_get_int( ber, boolval );
}
ber_tag_t
......@@ -716,8 +644,6 @@ ber_first_element(
ber_len_t *len,
char **last )
{
assert( ber != NULL );
assert( len != NULL );
assert( last != NULL );
/* skip the sequence header, use the len to mark where to stop */
......@@ -725,11 +651,10 @@ ber_first_element(
*last = NULL;
return LBER_DEFAULT;
}
ber->ber_tag = *(unsigned char *)ber->ber_ptr;
*last = ber->ber_ptr + *len;
if ( *last == ber->ber_ptr ) {
if ( *len == 0 ) {
return LBER_DEFAULT;
}
......@@ -743,9 +668,7 @@ ber_next_element(
LDAP_CONST char *last )
{
assert( ber != NULL );
assert( len != NULL );
assert( last != NULL );
assert( LBER_VALID( ber ) );
if ( ber->ber_ptr >= last ) {
......@@ -763,8 +686,8 @@ ber_scanf ( BerElement *ber,
{
va_list ap;
LDAP_CONST char *fmt_reset;
char *s, **ss;
struct berval **bvp, *bval;
char *s, **ss, ***sss;
struct berval *bval, **bvp, ***bvpp;
ber_int_t *i;
ber_len_t *l;
ber_tag_t *t;
......@@ -775,7 +698,6 @@ ber_scanf ( BerElement *ber,
assert( ber != NULL );
assert( fmt != NULL );
assert( LBER_VALID( ber ) );
fmt_reset = fmt;
......@@ -823,7 +745,7 @@ ber_scanf ( BerElement *ber,
break;
case 'e': /* enumerated */
case 'i': /* int */
case 'i': /* integer */
i = va_arg( ap, ber_int_t * );
rc = ber_get_int( ber, i );
break;
......@@ -924,9 +846,13 @@ ber_scanf ( BerElement *ber,
case '{': /* begin sequence */
case '[': /* begin set */
if ( *(fmt + 1) != 'v' && *(fmt + 1) != 'V'
&& *(fmt + 1) != 'W' && *(fmt + 1) != 'M' )
switch ( fmt[1] ) {
case 'v': case 'V': case 'W': case 'M':
break;
default:
rc = ber_skip_tag( ber, &len );
break;
}
break;
case '}': /* end sequence */
......@@ -944,6 +870,7 @@ ber_scanf ( BerElement *ber,
}
va_end( ap );
if ( rc == LBER_DEFAULT ) {
/*
* Error. Reclaim malloced memory that was given to the caller.
......@@ -966,42 +893,48 @@ ber_scanf ( BerElement *ber,
case 'a': /* octet string - allocate storage as needed */
case 'A':
ss = va_arg( ap, char ** );
if ( *ss ) {
LBER_FREE( *ss );
*ss = NULL;
}
ber_memfree_x( *ss, ber->ber_memctx );
*ss = NULL;
break;
case 'b': /* boolean */
case 'e': /* enumerated */