From: Kurt Zeilenga Date: Thu, 20 May 1999 21:21:57 +0000 (+0000) Subject: Fix initialization bug in ber_init_w_nullc() X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~36 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=68fb44b45023a6d50a009cc4f2488c2e72bb8ef4;p=openldap Fix initialization bug in ber_init_w_nullc() Added assert(), additional comments, and a few minor adjustments. --- diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index bddb359d08..2e8bf8b330 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -127,7 +127,11 @@ ber_peek_tag( unsigned long *len ) { unsigned long tag; - BerElement *ber = ber_dup( ber_in ); + BerElement *ber; + + assert( ber_in != NULL ); + + ber = ber_dup( ber_in ); if( ber == NULL ) { return LBER_ERROR; @@ -183,6 +187,8 @@ ber_get_int( BerElement *ber, long *num ) { unsigned long tag, len; + assert( ber != NULL ); + if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) return( LBER_DEFAULT ); @@ -200,6 +206,8 @@ ber_get_stringb( BerElement *ber, char *buf, unsigned long *len ) char *transbuf; #endif /* STR_TRANSLATION */ + assert( ber != NULL ); + if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) return( LBER_DEFAULT ); if ( datalen > (*len - 1) ) @@ -238,6 +246,9 @@ ber_get_stringa( BerElement *ber, char **buf ) { unsigned long datalen, tag; + assert( ber != NULL ); + assert( buf != NULL ); + if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) { *buf = NULL; return( LBER_DEFAULT ); @@ -274,6 +285,9 @@ ber_get_stringal( BerElement *ber, struct berval **bv ) { unsigned long len, tag; + assert( ber != NULL ); + assert( bv != NULL ); + if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) { *bv = NULL; return( LBER_DEFAULT ); @@ -319,6 +333,10 @@ ber_get_bitstringa( BerElement *ber, char **buf, unsigned long *blen ) unsigned long datalen, tag; unsigned char unusedbits; + assert( ber != NULL ); + assert( buf != NULL ); + assert( blen != NULL ); + if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) { *buf = NULL; return( LBER_DEFAULT ); @@ -349,6 +367,8 @@ ber_get_null( BerElement *ber ) { unsigned long len, tag; + assert( ber != NULL ); + if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) return( LBER_DEFAULT ); @@ -364,6 +384,9 @@ ber_get_boolean( BerElement *ber, int *boolval ) long longbool; int rc; + assert( ber != NULL ); + assert( boolval != NULL ); + rc = ber_get_int( ber, &longbool ); *boolval = longbool; @@ -373,6 +396,10 @@ ber_get_boolean( BerElement *ber, int *boolval ) unsigned long ber_first_element( BerElement *ber, unsigned long *len, char **last ) { + assert( ber != NULL ); + assert( len != NULL ); + assert( last != NULL ); + /* skip the sequence header, use the len to mark where to stop */ if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) { *last = NULL; @@ -395,6 +422,10 @@ ber_first_element( BerElement *ber, unsigned long *len, char **last ) unsigned long ber_next_element( BerElement *ber, unsigned long *len, char *last ) { + assert( ber != NULL ); + assert( len != NULL ); + assert( last != NULL ); + if ( ber->ber_ptr == last ) { #ifdef LBER_END_SEQORSET return( LBER_END_SEQORSET ); @@ -431,8 +462,6 @@ va_dcl long *l; unsigned long rc, tag, len; - assert( ber != NULL ); - #ifdef HAVE_STDARG va_start( ap, fmt ); #else diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c index a4e6bc93db..176a965fb0 100644 --- a/libraries/liblber/io.c +++ b/libraries/liblber/io.c @@ -240,13 +240,13 @@ ber_alloc_t( int options ) } BerElement * -ber_alloc( void ) +ber_alloc( void ) /* deprecated */ { return( ber_alloc_t( 0 ) ); } BerElement * -der_alloc( void ) +der_alloc( void ) /* deprecated */ { return( ber_alloc_t( LBER_USE_DER ) ); } @@ -258,8 +258,9 @@ ber_dup( LDAP_CONST BerElement *ber ) assert( ber != NULL ); - if ( (new = ber_alloc()) == NULL ) + if ( (new = ber_alloc_t( ber->ber_options )) == NULL ) { return( NULL ); + } *new = *ber; @@ -276,6 +277,7 @@ ber_init_w_nullc( BerElement *ber, int options ) (void) memset( (char *)ber, '\0', sizeof( BerElement )); ber->ber_tag = LBER_DEFAULT; ber->ber_options = (char) options; + ber->ber_debug = ber_int_debug; } /* New C-API ber_init() */