]> git.sur5r.net Git - openldap/commitdiff
more coverity issues
authorPierangelo Masarati <ando@openldap.org>
Fri, 14 Apr 2006 00:17:27 +0000 (00:17 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 14 Apr 2006 00:17:27 +0000 (00:17 +0000)
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/config.c
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/map.c
servers/slapd/overlays/rwm.c
servers/slapd/overlays/rwmmap.c

index 20b983e0db61e47e835b6c019368fce8697a1483..131219683fc0db4b607ae0b9be4d11e7ad485cdb 100644 (file)
@@ -1713,6 +1713,7 @@ free_ber:;
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        op->o_tmpfree( ctrls, op->o_tmpmemctx );
                        ctrls = NULL;
+                       goto done;
                }
 
        } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
@@ -1725,6 +1726,7 @@ free_ber:;
                if ( strncasecmp( authzID.bv_val, "dn:", STRLENOF( "dn:" ) ) != 0 ) {
                        op->o_tmpfree( ctrls[ 0 ]->ldctl_value.bv_val, op->o_tmpmemctx );
                        op->o_tmpfree( ctrls, op->o_tmpmemctx );
+                       ctrls = NULL;
                        rs->sr_err = LDAP_PROTOCOL_ERROR;
                        goto done;
                }
index d728a584f6fc5fba21b51cc2102d072bf18bbcdb..ddf4e77ae086eb317106653bdf3c03f3b6f137a5 100644 (file)
@@ -1150,7 +1150,7 @@ done_url:;
                        } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
                                char    *argvi = c->argv[ i ] + STRLENOF( "flags=" );
                                char    **flags = ldap_str2charray( argvi, "," );
-                               int     j;
+                               int     j, err = 0;
 
                                if ( flags == NULL ) {
                                        snprintf( c->msg, sizeof( c->msg ),
@@ -1162,6 +1162,7 @@ done_url:;
                                }
 
                                for ( j = 0; flags[ j ] != NULL; j++ ) {
+
                                        if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
                                                li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
 
@@ -1178,9 +1179,12 @@ done_url:;
                                                                        "in \"idassert-mode <args>\" "
                                                                        "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
                                                                        c->fname, c->lineno, 0 );
-                                                       return 1;
+                                                       err = 1;
+                                                       break;
+
+                                               } else {
+                                                       li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
                                                }
-                                               li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
 
                                        } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
                                                if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
@@ -1189,9 +1193,12 @@ done_url:;
                                                                "in \"idassert-mode <args>\" "
                                                                "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
                                                                c->fname, c->lineno, 0 );
-                                                       return 1;
+                                                       err = 1;
+                                                       break;
+
+                                               } else {
+                                                       li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
                                                }
-                                               li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
 
                                        } else {
                                                snprintf( c->msg, sizeof( c->msg ),
@@ -1199,12 +1206,15 @@ done_url:;
                                                        "unknown flag \"%s\"",
                                                        flags[ j ] );
                                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
-                                               ldap_charray_free( flags );
-                                               return 1;
+                                               err = 1;
+                                               break;
                                        }
                                }
 
                                ldap_charray_free( flags );
+                               if ( err ) {
+                                       return 1;
+                               }
 
                        } else if ( bindconf_parse( c->argv[ i ], &li->li_idassert ) ) {
                                return 1;
index 6a915f9efa03040a8f95896930bcfbafbca94d3e..1993e4aeb148c271017667f487315b5df6be25d8 100644 (file)
@@ -668,7 +668,6 @@ meta_back_dobind(
                metatarget_t            *mt = &mi->mi_targets[ i ];
                metasingleconn_t        *msc = &mc->mc_conns[ i ];
                int                     rc, do_retry = 1;
-               char                    *rootdn = NULL;
 
                /*
                 * Not a candidate
@@ -735,7 +734,7 @@ retry:;
 
                        snprintf( buf, sizeof( buf ),
                                "meta_back_dobind[%d]: (%s) err=%d (%s).",
-                               i, rootdn ? rootdn : "anonymous",
+                               i, isroot ? op->o_bd->be_rootdn.bv_val : "anonymous",
                                rc, ldap_err2string( rc ) );
                        Debug( LDAP_DEBUG_ANY,
                                "%s %s\n",
@@ -762,11 +761,11 @@ retry:;
                        "%s meta_back_dobind[%d]: "
                        "(%s)\n",
                        op->o_log_prefix, i,
-                       rootdn ? rootdn : "anonymous" );
+                       isroot ? op->o_bd->be_rootdn.bv_val : "anonymous" );
 
                ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
                LDAP_BACK_CONN_BINDING_CLEAR( msc );
-               if ( rootdn ) {
+               if ( isroot ) {
                        LDAP_BACK_CONN_ISBOUND_SET( msc );
                } else {
                        LDAP_BACK_CONN_ISANON_SET( msc );
index b12abce6cd39be32a7bbfc2ac0c803f6ff3f0ae7..912bd1671ded37bcf0150c5d4aa7436559be663e 100644 (file)
@@ -297,6 +297,9 @@ ldap_back_int_filter_map_rewrite(
                        ber_bvnone = BER_BVC( "(?=none)" );
        ber_len_t       len;
 
+       assert( fstr != NULL );
+       BER_BVZERO( fstr );
+
        if ( f == NULL ) {
                ber_dupbv( fstr, &ber_bvnone );
                return LDAP_OTHER;
index 5626eb3c710d0f5b0ec6501b1ec19976c62706a8..95cc42225d6d739402b72b297ac03e1f61fc5635 100644 (file)
@@ -26,6 +26,9 @@
 #include "slap.h"
 #include "rwm.h"
 
+static int
+rwm_db_destroy( BackendDB *be );
+
 static int
 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie )
 {
@@ -1150,12 +1153,11 @@ rwm_chk_referrals( Operation *op, SlapReply *rs )
 
 static int
 rwm_rw_config(
-    BackendDB  *be,
-    const char *fname,
-    int                lineno,
-    int                argc,
-    char       **argv
-)
+       BackendDB       *be,
+       const char      *fname,
+       int             lineno,
+       int             argc,
+       char            **argv )
 {
 #ifdef ENABLE_REWRITE
        slap_overinst           *on = (slap_overinst *) be->bd_info;
@@ -1175,12 +1177,11 @@ rwm_rw_config(
 
 static int
 rwm_suffixmassage_config(
-    BackendDB  *be,
-    const char *fname,
-    int                lineno,
-    int                argc,
-    char       **argv
-)
+       BackendDB       *be,
+       const char      *fname,
+       int             lineno,
+       int             argc,
+       char            **argv )
 {
        slap_overinst           *on = (slap_overinst *) be->bd_info;
        struct ldaprwmap        *rwmap = 
@@ -1269,12 +1270,11 @@ rwm_suffixmassage_config(
 
 static int
 rwm_m_config(
-    BackendDB  *be,
-    const char *fname,
-    int                lineno,
-    int                argc,
-    char       **argv
-)
+       BackendDB       *be,
+       const char      *fname,
+       int             lineno,
+       int             argc,
+       char            **argv )
 {
        slap_overinst           *on = (slap_overinst *) be->bd_info;
        struct ldaprwmap        *rwmap = 
@@ -1352,12 +1352,11 @@ rwm_response( Operation *op, SlapReply *rs )
 
 static int
 rwm_db_config(
-    BackendDB  *be,
-    const char *fname,
-    int                lineno,
-    int                argc,
-    char       **argv
-)
+       BackendDB       *be,
+       const char      *fname,
+       int             lineno,
+       int             argc,
+       char            **argv )
 {
        slap_overinst           *on = (slap_overinst *) be->bd_info;
        struct ldaprwmap        *rwmap = 
@@ -1425,8 +1424,7 @@ rwm_db_config(
 
 static int
 rwm_db_init(
-       BackendDB *be
-)
+       BackendDB       *be )
 {
        slap_overinst           *on = (slap_overinst *) be->bd_info;
        struct ldapmapping      *mapping = NULL;
@@ -1434,14 +1432,15 @@ rwm_db_init(
 #ifdef ENABLE_REWRITE
        char                    *rargv[ 3 ];
 #endif /* ENABLE_REWRITE */
+       int                     rc = 0;
 
        rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
 
 #ifdef ENABLE_REWRITE
        rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
        if ( rwmap->rwm_rw == NULL ) {
-               ch_free( rwmap );
-               return -1;
+               rc = -1;
+               goto error_return;
        }
 
        /* this rewriteContext by default must be null;
@@ -1460,18 +1459,23 @@ rwm_db_init(
        if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS ||
                        rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS )
        {
-               return 1;
+               rc = 1;
+               goto error_return;
        }
 
+error_return:;
        on->on_bi.bi_private = (void *)rwmap;
 
-       return 0;
+       if ( rc ) {
+               (void)rwm_db_destroy( be );
+       }
+
+       return rc;
 }
 
 static int
 rwm_db_destroy(
-       BackendDB *be
-)
+       BackendDB       *be )
 {
        slap_overinst   *on = (slap_overinst *) be->bd_info;
        int             rc = 0;
@@ -1503,8 +1507,11 @@ rwm_db_destroy(
 
 static slap_overinst rwm = { { NULL } };
 
+#if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
+static
+#endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
 int
-rwm_initialize(void)
+rwm_initialize( void )
 {
        memset( &rwm, 0, sizeof( slap_overinst ) );
 
index 13a261dcc2396c463ae8fb40de1d7c9a0b8df657..dce3a95f73087fdd218f13695ac00cf23b289758 100644 (file)
@@ -84,6 +84,7 @@ rwm_map_init( struct ldapmap *lm, struct ldapmapping **m )
        /* FIXME: I don't think this is needed any more... */
        rc = slap_str2ad( "objectClass", &mapping[0].m_src_ad, &text );
        if ( rc != LDAP_SUCCESS ) {
+               ch_free( mapping );
                return rc;
        }
 
@@ -112,6 +113,10 @@ rwm_mapping( struct ldapmap *map, struct berval *s, struct ldapmapping **m, int
        Avlnode *tree;
        struct ldapmapping fmapping;
 
+       if ( map == NULL ) {
+               return 0;
+       }
+
        assert( m != NULL );
 
        if ( remap == RWM_REMAP ) {
@@ -156,12 +161,11 @@ rwm_map( struct ldapmap *map, struct berval *s, struct berval *bv, int remap )
  */
 int
 rwm_map_attrnames(
-               struct ldapmap *at_map,
-               struct ldapmap *oc_map,
-               AttributeName *an,
-               AttributeName **anp,
-               int remap
-)
+       struct ldapmap  *at_map,
+       struct ldapmap  *oc_map,
+       AttributeName   *an,
+       AttributeName   **anp,
+       int             remap )
 {
        int             i, j;
 
@@ -246,7 +250,6 @@ rwm_map_attrnames(
                        at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
                
                        if ( at_drop_missing || !m ) {
-
                                oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
 
                                /* if both at_map and oc_map required to drop missing,
@@ -301,6 +304,7 @@ rwm_map_attrnames(
        if ( j == 0 && i != 0 ) {
                memset( &(*anp)[0], 0, sizeof( AttributeName ) );
                BER_BVSTR( &(*anp)[0].an_name, LDAP_NO_ATTRS );
+               j = 1;
        }
        memset( &(*anp)[j], 0, sizeof( AttributeName ) );
 
@@ -309,11 +313,10 @@ rwm_map_attrnames(
 
 int
 rwm_map_attrs(
-               struct ldapmap *at_map,
-               AttributeName *an,
-               int remap,
-               char ***mapped_attrs
-)
+       struct ldapmap  *at_map,
+       AttributeName   *an,
+       int             remap,
+       char            ***mapped_attrs )
 {
        int i, j;
        char **na;
@@ -323,9 +326,8 @@ rwm_map_attrs(
                return LDAP_SUCCESS;
        }
 
-       for ( i = 0; !BER_BVISNULL( &an[ i ].an_name ); i++ ) {
-               /*  */
-       }
+       for ( i = 0; !BER_BVISNULL( &an[ i ].an_name ); i++ )
+               /* count'em */ ;
 
        na = (char **)ch_calloc( i + 1, sizeof( char * ) );
        if ( na == NULL ) {
@@ -361,12 +363,12 @@ rwm_map_attrs(
 
 static int
 map_attr_value(
-               dncookie                *dc,
-               AttributeDescription    **adp,
-               struct berval           *mapped_attr,
-               struct berval           *value,
-               struct berval           *mapped_value,
-               int                     remap )
+       dncookie                *dc,
+       AttributeDescription    **adp,
+       struct berval           *mapped_attr,
+       struct berval           *value,
+       struct berval           *mapped_value,
+       int                     remap )
 {
        struct berval           vtmp = BER_BVNULL;
        int                     freeval = 0;
@@ -442,10 +444,10 @@ map_attr_value(
 
 static int
 rwm_int_filter_map_rewrite(
-               Operation               *op,
-               dncookie                *dc,
-               Filter                  *f,
-               struct berval           *fstr )
+       Operation               *op,
+       dncookie                *dc,
+       Filter                  *f,
+       struct berval           *fstr )
 {
        int             i;
        Filter          *p;
@@ -468,6 +470,9 @@ rwm_int_filter_map_rewrite(
                        ber_bvnone = BER_BVC( "(?=none)" );
        ber_len_t       len;
 
+       assert( fstr != NULL );
+       BER_BVZERO( fstr );
+
        if ( f == NULL ) {
                ber_dupbv( fstr, &ber_bvnone );
                return LDAP_OTHER;
@@ -720,10 +725,10 @@ computed:;
 
 int
 rwm_filter_map_rewrite(
-               Operation               *op,
-               dncookie                *dc,
-               Filter                  *f,
-               struct berval           *fstr )
+       Operation               *op,
+       dncookie                *dc,
+       Filter                  *f,
+       struct berval           *fstr )
 {
        int             rc;
        dncookie        fdc;
@@ -1077,8 +1082,7 @@ rwm_dnattr_rewrite(
 int
 rwm_referral_result_rewrite(
        dncookie                *dc,
-       BerVarray               a_vals
-)
+       BerVarray               a_vals )
 {
        int             i, last;
 
@@ -1156,8 +1160,7 @@ rwm_referral_result_rewrite(
 int
 rwm_dnattr_result_rewrite(
        dncookie                *dc,
-       BerVarray               a_vals
-)
+       BerVarray               a_vals )
 {
        int             i, last;