X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fgetattr.c;h=dd18acd969eb0012ca6fe2baff38ae9e68fe182c;hb=b4243bc119b2f88318103176c7c671662c9ff371;hp=d2a478c63424766acf1f4fba8b9185a58e4a3f80;hpb=f4f093054a14ba3438f95932644da25204657489;p=openldap diff --git a/libraries/libldap/getattr.c b/libraries/libldap/getattr.c index d2a478c634..dd18acd969 100644 --- a/libraries/libldap/getattr.c +++ b/libraries/libldap/getattr.c @@ -1,6 +1,6 @@ /* $OpenLDAP$ */ /* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ /* Portions @@ -26,7 +26,7 @@ ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout ) { int rc; ber_tag_t tag; - ber_len_t len; + ber_len_t len = 0; char *attr; BerElement *ber; @@ -51,20 +51,13 @@ ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout ) * us at the first attribute. */ - tag = ber_scanf( ber, "{xl{" /*}}*/, &attr, &len ); + tag = ber_scanf( ber, "{xl{" /*}}*/, &len ); if( tag == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; ber_free( ber, 0 ); - return NULL; - } - -#if 0 - if( len == 0 ) { return NULL; } -#endif - -#if 0 + /* set the length to avoid overrun */ rc = ber_set_option( ber, LBER_OPT_REMAINING_BYTES, &len ); if( rc != LBER_OPT_SUCCESS ) { @@ -72,7 +65,13 @@ ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout ) ber_free( ber, 0 ); return NULL; } -#endif + + if ( ber_pvt_ber_remaining( ber ) == 0 ) { + assert( len == 0 ); + ber_free( ber, 0 ); + return NULL; + } + assert( len != 0 ); /* snatch the first attribute */ tag = ber_scanf( ber, "{ax}", &attr ); @@ -100,11 +99,9 @@ ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber ) assert( entry != NULL ); assert( ber != NULL ); -#if 0 if ( ber_pvt_ber_remaining( ber ) == 0 ) { return NULL; } -#endif /* skip sequence, snarf attribute type, skip values */ tag = ber_scanf( ber, "{ax}", &attr );