From bace581e645a233591991cb7ab108f4d50cc6271 Mon Sep 17 00:00:00 2001 From: Howard Chu <hyc@symas.com> Date: Sun, 18 Jan 2015 14:17:44 +0000 Subject: [PATCH] Minor cleanup (coverity) --- servers/slapd/overlays/constraint.c | 10 ---------- servers/slapd/overlays/dynlist.c | 21 ++++++++++++++++----- servers/slapd/overlays/pcache.c | 9 ++++++++- servers/slapd/overlays/ppolicy.c | 14 ++++++++++++-- servers/slapd/overlays/rwmmap.c | 5 ++++- servers/slapd/overlays/translucent.c | 4 ++-- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/servers/slapd/overlays/constraint.c b/servers/slapd/overlays/constraint.c index 096f32aa79..33323e399d 100644 --- a/servers/slapd/overlays/constraint.c +++ b/servers/slapd/overlays/constraint.c @@ -980,16 +980,6 @@ constraint_update( Operation *op, SlapReply *rs ) /* Do we need to count attributes? */ for(cp = c; cp; cp = cp->ap_next) { if (cp->type == CONSTRAINT_COUNT) { - if (rc != 0 || target_entry == NULL) { - Debug(LDAP_DEBUG_TRACE, - "==> constraint_update rc = %d DN=\"%s\"%s\n", - rc, op->o_req_ndn.bv_val, - target_entry ? "" : " not found" ); - if ( rc == 0 ) - rc = LDAP_CONSTRAINT_VIOLATION; - goto mod_violation; - } - if (cp->restrict_lud && constraint_check_restrict(op, cp, target_entry) == 0) { continue; } diff --git a/servers/slapd/overlays/dynlist.c b/servers/slapd/overlays/dynlist.c index b5146ed786..bdd9f2555f 100644 --- a/servers/slapd/overlays/dynlist.c +++ b/servers/slapd/overlays/dynlist.c @@ -1158,6 +1158,12 @@ done_uri:; filter_free( filter ); } + while ( dlm != NULL ) { + dlml = dlm; + dlm = dlm->dlm_next; + ch_free( dlml ); + } + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); @@ -1174,7 +1180,8 @@ done_uri:; c->argv[ attridx ] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); - return 1; + rc = 1; + goto done_uri; } if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) { @@ -1184,7 +1191,8 @@ done_uri:; c->argv[ attridx ] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); - return 1; + rc = 1; + goto done_uri; } attridx++; @@ -1213,7 +1221,8 @@ done_uri:; i - 3, c->argv[ i ] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); - return 1; + rc = 1; + goto done_uri; } arg = cp + 1; } @@ -1226,7 +1235,8 @@ done_uri:; i - 3, c->argv[ i ] ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); - return 1; + rc = 1; + goto done_uri; } dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) ); @@ -1255,7 +1265,8 @@ done_uri:; c->valx ); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); - return 1; + rc = 1; + goto done_uri; } dlip = &(*dlip)->dli_next; } diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 19ead34291..2261ec2edb 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -457,8 +457,13 @@ ftemp_attrs( struct berval *ftemp, struct berval *template, *t1++ = *p1++; p2 = strchr( p1, '=' ); - if ( !p2 ) + if ( !p2 ) { + if ( !descs ) { + ch_free( temp2 ); + return -1; + } break; + } i = p2 - p1; AC_MEMCPY( t1, p1, i ); t1 += i; @@ -470,6 +475,7 @@ ftemp_attrs( struct berval *ftemp, struct berval *template, ad = NULL; i = slap_bv2ad( &bv, &ad, text ); if ( i ) { + ch_free( temp2 ); ch_free( descs ); return -1; } @@ -565,6 +571,7 @@ bottom: } if ( !t_cnt ) { *text = "couldn't parse template"; + ch_free(attrs); return -1; } if ( !got_oc && !( set->flags & PC_GOT_OC )) { diff --git a/servers/slapd/overlays/ppolicy.c b/servers/slapd/overlays/ppolicy.c index 19ffdb6f17..1c365f473e 100644 --- a/servers/slapd/overlays/ppolicy.c +++ b/servers/slapd/overlays/ppolicy.c @@ -378,6 +378,7 @@ create_passcontrol( Operation *op, int exptime, int grace, LDAPPasswordPolicyErr BerElement *ber = (BerElement *) &berbuf, *b2 = (BerElement *) &bb2; LDAPControl c = { 0 }, *cp; struct berval bv; + int rc; BER_BVZERO( &c.ldctl_value ); @@ -387,15 +388,23 @@ create_passcontrol( Operation *op, int exptime, int grace, LDAPPasswordPolicyErr if ( exptime >= 0 ) { ber_init2( b2, NULL, LBER_USE_DER ); ber_printf( b2, "ti", PPOLICY_EXPIRE, exptime ); - ber_flatten2( b2, &bv, 1 ); + rc = ber_flatten2( b2, &bv, 1 ); (void)ber_free_buf(b2); + if (rc == -1) { + cp = NULL; + goto fail; + } ber_printf( ber, "tO", PPOLICY_WARNING, &bv ); ch_free( bv.bv_val ); } else if ( grace > 0 ) { ber_init2( b2, NULL, LBER_USE_DER ); ber_printf( b2, "ti", PPOLICY_GRACE, grace ); - ber_flatten2( b2, &bv, 1 ); + rc = ber_flatten2( b2, &bv, 1 ); (void)ber_free_buf(b2); + if (rc == -1) { + cp = NULL; + goto fail; + } ber_printf( ber, "tO", PPOLICY_WARNING, &bv ); ch_free( bv.bv_val ); } @@ -414,6 +423,7 @@ create_passcontrol( Operation *op, int exptime, int grace, LDAPPasswordPolicyErr cp->ldctl_value.bv_val = (char *)&cp[1]; cp->ldctl_value.bv_len = c.ldctl_value.bv_len; AC_MEMCPY( cp->ldctl_value.bv_val, c.ldctl_value.bv_val, c.ldctl_value.bv_len ); +fail: (void)ber_free_buf(ber); return cp; diff --git a/servers/slapd/overlays/rwmmap.c b/servers/slapd/overlays/rwmmap.c index 4594353c98..c12d413759 100644 --- a/servers/slapd/overlays/rwmmap.c +++ b/servers/slapd/overlays/rwmmap.c @@ -215,7 +215,9 @@ rwm_map_attrnames( return LDAP_NO_MEMORY; } - for ( i = 0, j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) { + j = 0; + if ( an != NULL ) { + for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) { struct ldapmapping *m; int at_drop_missing = 0, oc_drop_missing = 0; @@ -331,6 +333,7 @@ rwm_map_attrnames( } } } + } if ( op->o_bd->be_extra_anlist != NULL ) { /* we assume be_extra_anlist are already mapped */ diff --git a/servers/slapd/overlays/translucent.c b/servers/slapd/overlays/translucent.c index a8846b10a1..b7de2cb3be 100644 --- a/servers/slapd/overlays/translucent.c +++ b/servers/slapd/overlays/translucent.c @@ -420,12 +420,12 @@ static int translucent_modify(Operation *op, SlapReply *rs) { op->o_bd = &ov->db; ov->db.be_acl = op->o_bd->be_acl; rc = ov->db.bd_info->bi_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &re); + op->o_bd = db; if(rc != LDAP_SUCCESS || re == NULL ) { send_ldap_error((op), rs, LDAP_NO_SUCH_OBJECT, "attempt to modify nonexistent local record"); return(rs->sr_err); } - op->o_bd = db; /* ** fetch entry from local backend; ** if it exists: @@ -788,7 +788,7 @@ static int translucent_search_cb(Operation *op, SlapReply *rs) { if ( rs->sr_type == REP_RESULT && ( tc->step & USE_LIST )) return 0; - if(!op || !rs || rs->sr_type != REP_SEARCH || !rs->sr_entry) + if(rs->sr_type != REP_SEARCH || !rs->sr_entry) return(SLAP_CB_CONTINUE); Debug(LDAP_DEBUG_TRACE, "==> translucent_search_cb: %s\n", -- GitLab