From 2c7dae116b5a9f320356826bb32232fb06997d8b Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 6 Jun 2002 00:26:50 +0000 Subject: [PATCH] More argument handling updates (don't check what we expect applications to check). --- libraries/libldap/cache.c | 33 +++++++++++++++++++++++++++++++++ libraries/libldap/compare.c | 4 ++++ libraries/libldap/controls.c | 3 +++ libraries/libldap/dnssrv.c | 13 ++++++------- libraries/libldap/getentry.c | 14 +------------- libraries/libldap/messages.c | 16 +++------------- libraries/libldap/references.c | 10 ++-------- 7 files changed, 52 insertions(+), 41 deletions(-) diff --git a/libraries/libldap/cache.c b/libraries/libldap/cache.c index ccfc763092..83e6e7953c 100644 --- a/libraries/libldap/cache.c +++ b/libraries/libldap/cache.c @@ -37,6 +37,9 @@ static void uncache_entry_or_req LDAP_P(( LDAP *ld, LDAP_CONST char *dn, ber_in int ldap_enable_cache( LDAP *ld, long timeout, ber_len_t maxmem ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifndef LDAP_NOCACHE if ( ld->ld_cache == NULL ) { if (( ld->ld_cache = (LDAPCache *)LDAP_MALLOC( sizeof( LDAPCache ))) @@ -62,6 +65,9 @@ ldap_enable_cache( LDAP *ld, long timeout, ber_len_t maxmem ) void ldap_disable_cache( LDAP *ld ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifndef LDAP_NOCACHE if ( ld->ld_cache != NULL ) { ld->ld_cache->lc_enabled = 0; @@ -74,6 +80,9 @@ ldap_disable_cache( LDAP *ld ) void ldap_set_cache_options( LDAP *ld, unsigned long opts ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifndef LDAP_NOCACHE if ( ld->ld_cache != NULL ) { ld->ld_cache->lc_options = opts; @@ -85,6 +94,9 @@ ldap_set_cache_options( LDAP *ld, unsigned long opts ) void ldap_destroy_cache( LDAP *ld ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifndef LDAP_NOCACHE if ( ld->ld_cache != NULL ) { ldap_flush_cache( ld ); @@ -102,6 +114,9 @@ ldap_flush_cache( LDAP *ld ) int i; LDAPMessage *m, *next; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifdef NEW_LOGGING LDAP_LOG (( "cache", LDAP_LEVEL_ENTRY, "ldap_flush_cache\n" )); #else @@ -134,6 +149,9 @@ ldap_flush_cache( LDAP *ld ) void ldap_uncache_request( LDAP *ld, int msgid ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifndef LDAP_NOCACHE #ifdef NEW_LOGGING LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, @@ -152,6 +170,10 @@ ldap_uncache_request( LDAP *ld, int msgid ) void ldap_uncache_entry( LDAP *ld, LDAP_CONST char *dn ) { + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( dn != NULL ); + #ifndef LDAP_NOCACHE #ifdef NEW_LOGGING LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, @@ -240,6 +262,9 @@ ldap_add_request_to_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request ) LDAPMessage *new; ber_len_t len; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + #ifdef NEW_LOGGING LDAP_LOG (( "cache", LDAP_LEVEL_ENTRY, "ldap_add_request_to_cache\n" )); #else @@ -288,6 +313,10 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result ) LDAPMessage *m, **mp, *req, *new, *prev; int err, keep; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( result != NULL ); + #ifdef NEW_LOGGING LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, "ldap_add_result_to_cache: id %ld, type %ld\n", @@ -447,6 +476,10 @@ ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request ) int first, hash; time_t c_time; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( request != NULL ); + #ifdef NEW_LOGGING LDAP_LOG (( "cache", LDAP_LEVEL_ENTRY, "ldap_check_cache\n" )); #else diff --git a/libraries/libldap/compare.c b/libraries/libldap/compare.c index 83d7ec125e..4af59d01b8 100644 --- a/libraries/libldap/compare.c +++ b/libraries/libldap/compare.c @@ -131,6 +131,8 @@ ldap_compare( int msgid; struct berval bvalue; + assert( value != NULL ); + bvalue.bv_val = (char *) value; bvalue.bv_len = (value == NULL) ? 0 : strlen( value ); @@ -171,6 +173,8 @@ ldap_compare_s( { struct berval bvalue; + assert( value != NULL ); + bvalue.bv_val = (char *) value; bvalue.bv_len = (value == NULL) ? 0 : strlen( value ); diff --git a/libraries/libldap/controls.c b/libraries/libldap/controls.c index 76c2799236..12f455be98 100644 --- a/libraries/libldap/controls.c +++ b/libraries/libldap/controls.c @@ -38,6 +38,7 @@ ldap_int_put_controls( LDAPControl *const *c; assert( ld != NULL ); + assert( LDAP_VALID(ld) ); assert( ber != NULL ); if( ctrls == NULL ) { @@ -414,6 +415,7 @@ ldap_create_control( struct berval *bvalp; assert( requestOID != NULL ); + assert( ber != NULL ); assert( ctrlp != NULL ); ctrl = (LDAPControl *) LDAP_MALLOC( sizeof(LDAPControl) ); @@ -452,6 +454,7 @@ int ldap_int_client_controls( LDAP *ld, LDAPControl **ctrls ) LDAPControl *const *c; assert( ld != NULL ); + assert( LDAP_VALID(ld) ); if( ctrls == NULL ) { /* use default server controls */ diff --git a/libraries/libldap/dnssrv.c b/libraries/libldap/dnssrv.c index 1a763c9b6e..cc193e9358 100644 --- a/libraries/libldap/dnssrv.c +++ b/libraries/libldap/dnssrv.c @@ -41,9 +41,8 @@ int ldap_dn2domain( char *domain = NULL; char **dn; - if( dn_in == NULL || domainp == NULL ) { - return -1; - } + assert( dn_in != NULL ); + assert( domainp != NULL ); dn = ldap_explode_dn( dn_in, 0 ); @@ -147,12 +146,12 @@ int ldap_domain2dn( char *domain, *s, *tok_r, *dn; size_t loc; - if (domain_in == NULL || dnp == NULL) { - return LDAP_NO_MEMORY; - } + assert( domain_in != NULL ); + assert( dnp != NULL ); + domain = LDAP_STRDUP(domain_in); if (domain == NULL) { - return LDAP_NO_MEMORY; + return LDAP_NO_MEMORY; } dn = NULL; loc = 0; diff --git a/libraries/libldap/getentry.c b/libraries/libldap/getentry.c index b75a4403f4..4fb23eff6c 100644 --- a/libraries/libldap/getentry.c +++ b/libraries/libldap/getentry.c @@ -29,10 +29,6 @@ ldap_first_entry( LDAP *ld, LDAPMessage *chain ) assert( LDAP_VALID( ld ) ); assert( chain != NULL ); - if( ld == NULL || chain == NULL ) { - return NULL; - } - return chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ? chain : ldap_next_entry( ld, chain ); @@ -45,11 +41,7 @@ ldap_next_entry( LDAP *ld, LDAPMessage *entry ) assert( LDAP_VALID( ld ) ); assert( entry != NULL ); - if ( ld == NULL || entry == NULL ) { - return NULL; - } - - for ( + for( entry = entry->lm_chain; entry != NULL; entry = entry->lm_chain ) @@ -70,10 +62,6 @@ ldap_count_entries( LDAP *ld, LDAPMessage *chain ) assert( ld != NULL ); assert( LDAP_VALID( ld ) ); - if ( ld == NULL ) { - return -1; - } - for ( i = 0; chain != NULL; chain = chain->lm_chain ) { if( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) { i++; diff --git a/libraries/libldap/messages.c b/libraries/libldap/messages.c index 5c9a964741..bcb13a7f14 100644 --- a/libraries/libldap/messages.c +++ b/libraries/libldap/messages.c @@ -24,11 +24,8 @@ ldap_first_message( LDAP *ld, LDAPMessage *chain ) { assert( ld != NULL ); assert( LDAP_VALID( ld ) ); + assert( chain != NULL ); - if ( ld == NULL || chain == NULL ) { - return NULL; - } - return chain; } @@ -37,12 +34,9 @@ ldap_next_message( LDAP *ld, LDAPMessage *msg ) { assert( ld != NULL ); assert( LDAP_VALID( ld ) ); + assert( msg != NULL ); - if ( ld == NULL || msg == NULL || msg->lm_chain == NULL ) { - return NULL; - } - - return( msg->lm_chain ); + return msg->lm_chain; } int @@ -53,10 +47,6 @@ ldap_count_messages( LDAP *ld, LDAPMessage *chain ) assert( ld != NULL ); assert( LDAP_VALID( ld ) ); - if ( ld == NULL ) { - return -1; - } - for ( i = 0; chain != NULL; chain = chain->lm_chain ) { i++; } diff --git a/libraries/libldap/references.c b/libraries/libldap/references.c index 2aae3f469c..ff9b63fc0c 100644 --- a/libraries/libldap/references.c +++ b/libraries/libldap/references.c @@ -24,7 +24,7 @@ ldap_first_reference( LDAP *ld, LDAPMessage *chain ) { assert( ld != NULL ); assert( LDAP_VALID( ld ) ); - assert( chain != NULL ); + assert( chain != NULL ); return chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ? chain @@ -36,7 +36,7 @@ ldap_next_reference( LDAP *ld, LDAPMessage *ref ) { assert( ld != NULL ); assert( LDAP_VALID( ld ) ); - assert( ref != NULL ); + assert( ref != NULL ); for ( ref = ref->lm_chain; @@ -58,13 +58,7 @@ ldap_count_references( LDAP *ld, LDAPMessage *chain ) assert( ld != NULL ); assert( LDAP_VALID( ld ) ); - assert( chain != NULL ); - - if ( ld == NULL ) { - return -1; - } - for ( i = 0; chain != NULL; chain = chain->lm_chain ) { if( chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ) { i++; -- 2.39.5