Commit fac36dcb authored by Hallvard Furuseth's avatar Hallvard Furuseth
Browse files

ITS#6932: Clean up strange asserts & nearby code.

Mostly found by Klocwork: Issues #213,298-300,331,342-343,374,390,410.
parent 06dca785
......@@ -112,11 +112,10 @@ autogroup_add_member_to_group( Operation *op, BerValue *dn, BerValue *ndn, autog
slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
Operation o = *op;
Debug(LDAP_DEBUG_TRACE, "==> autogroup_add_member_to_group adding <%s> to <%s>\n",
dn->bv_val, age->age_dn.bv_val, 0);
assert( dn != NULL );
assert( ndn != NULL );
Debug(LDAP_DEBUG_TRACE, "==> autogroup_add_member_to_group adding <%s> to <%s>\n",
dn->bv_val, age->age_dn.bv_val, 0);
vals = (BerValue *)ch_calloc( 2, sizeof( BerValue ) );
nvals = (BerValue *)ch_calloc( 2, sizeof( BerValue ) );
......@@ -166,11 +165,10 @@ autogroup_add_member_values_to_group( Operation *op, Entry *e, autogroup_entry_t
slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
Operation o = *op;
assert( e != NULL );
Debug(LDAP_DEBUG_TRACE, "==> autogroup_add_member_values_to_group adding <%s> to <%s>\n",
e->e_name.bv_val, age->age_dn.bv_val, 0);
assert( e != NULL );
attr = attrs_find( e->e_attrs, attrdesc );
if (!attr) {
// Nothing to add
......@@ -279,11 +277,10 @@ autogroup_delete_member_values_from_group( Operation *op, Entry *e, autogroup_en
slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
Operation o = *op;
assert( e != NULL );
Debug(LDAP_DEBUG_TRACE, "==> autogroup_delete_member_values_from_group removing <%s> from <%s>\n",
e->e_name.bv_val, age->age_dn.bv_val, 0);
assert( e != NULL );
attr = attrs_find( e->e_attrs, attrdesc );
if (!attr) {
// Nothing to add
......
......@@ -135,7 +135,7 @@ ldap_sync_search_entry( ldap_sync_t *ls, LDAPMessage *res )
cookie = { 0 };
int state = -1;
ber_len_t len;
ldap_sync_refresh_t phase = ls->ls_refreshPhase;
ldap_sync_refresh_t phase;
#ifdef LDAP_SYNC_TRACE
fprintf( stderr, "\tgot LDAP_RES_SEARCH_ENTRY\n" );
......@@ -144,6 +144,8 @@ ldap_sync_search_entry( ldap_sync_t *ls, LDAPMessage *res )
assert( ls != NULL );
assert( res != NULL );
phase = ls->ls_refreshPhase;
/* OK */
/* extract:
......
......@@ -125,7 +125,7 @@ rewrite_rule_compile(
{
int flags = REWRITE_REGEX_EXTENDED | REWRITE_REGEX_ICASE;
int mode = REWRITE_RECURSE;
int max_passes = info->li_max_passes_per_rule;
int max_passes;
struct rewrite_rule *rule = NULL;
struct rewrite_subst *subst = NULL;
......@@ -137,11 +137,12 @@ rewrite_rule_compile(
assert( context != NULL );
assert( pattern != NULL );
assert( result != NULL );
/*
* A null flagstring should be allowed
*/
max_passes = info->li_max_passes_per_rule;
/*
* Take care of substitution string
*/
......
......@@ -245,10 +245,12 @@ ID bdb_tool_entry_next(
{
int rc;
ID id;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
struct bdb_info *bdb;
assert( be != NULL );
assert( slapMode & SLAP_TOOL_MODE );
bdb = (struct bdb_info *) be->be_private;
assert( bdb != NULL );
next:;
......@@ -634,7 +636,7 @@ ID bdb_tool_entry_put(
struct berval *text )
{
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
struct bdb_info *bdb;
DB_TXN *tid = NULL;
Operation op = {0};
Opheader ohdr = {0};
......@@ -649,6 +651,8 @@ ID bdb_tool_entry_put(
Debug( LDAP_DEBUG_TRACE, "=> " LDAP_XSTRING(bdb_tool_entry_put)
"( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 );
bdb = (struct bdb_info *) be->be_private;
if (! (slapMode & SLAP_TOOL_QUICK)) {
rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid,
bdb->bi_db_opflags );
......@@ -882,7 +886,7 @@ ID bdb_tool_entry_modify(
struct berval *text )
{
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
struct bdb_info *bdb;
DB_TXN *tid = NULL;
Operation op = {0};
Opheader ohdr = {0};
......@@ -900,6 +904,8 @@ ID bdb_tool_entry_modify(
"=> " LDAP_XSTRING(bdb_tool_entry_modify) "( %ld, \"%s\" )\n",
(long) e->e_id, e->e_dn, 0 );
bdb = (struct bdb_info *) be->be_private;
if (! (slapMode & SLAP_TOOL_QUICK)) {
if( cursor ) {
cursor->c_close( cursor );
......
......@@ -507,7 +507,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
{
backsql_at_map_rec *at = v_at;
backsql_srch_info *bsi = v_bsi;
backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
backsql_info *bi;
RETCODE rc;
SQLHSTMT sth = SQL_NULL_HSTMT;
BACKSQL_ROW_NTS row;
......@@ -531,12 +531,13 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
assert( at != NULL );
assert( bsi != NULL );
Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
"oc=\"%s\" attr=\"%s\" keyval=" BACKSQL_IDFMT "\n",
BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val,
BACKSQL_IDARG(bsi->bsi_c_eid->eid_keyval) );
bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
#ifdef BACKSQL_PRETTY_VALIDATE
validate = at->bam_true_ad->ad_type->sat_syntax->ssyn_validate;
pretty = at->bam_true_ad->ad_type->sat_syntax->ssyn_pretty;
......
......@@ -1794,9 +1794,9 @@ backend_access(
slap_mask_t *mask )
{
Entry *e = NULL;
void *o_priv = op->o_private, *e_priv = NULL;
void *o_priv, *e_priv = NULL;
int rc = LDAP_INSUFFICIENT_ACCESS;
Backend *be = op->o_bd;
Backend *be;
/* pedantic */
assert( op != NULL );
......@@ -1804,6 +1804,9 @@ backend_access(
assert( edn != NULL );
assert( access > ACL_NONE );
be = op->o_bd;
o_priv = op->o_private;
if ( !op->o_bd ) {
op->o_bd = select_backend( edn, 0 );
}
......
......@@ -474,15 +474,16 @@ over_acl_group(
{
slap_overinfo *oi;
slap_overinst *on;
BackendInfo *bi = op->o_bd->bd_info;
BackendInfo *bi;
BackendDB *be = op->o_bd, db;
int rc = SLAP_CB_CONTINUE;
/* FIXME: used to happen for instance during abandon
* when global overlays are used... */
assert( op->o_bd != NULL );
assert( be != NULL );
oi = op->o_bd->bd_info->bi_private;
bi = be->bd_info;
oi = bi->bi_private;
on = oi->oi_list;
for ( ; on; on = on->on_next ) {
......@@ -542,15 +543,16 @@ over_acl_attribute(
{
slap_overinfo *oi;
slap_overinst *on;
BackendInfo *bi = op->o_bd->bd_info;
BackendInfo *bi;
BackendDB *be = op->o_bd, db;
int rc = SLAP_CB_CONTINUE;
/* FIXME: used to happen for instance during abandon
* when global overlays are used... */
assert( op->o_bd != NULL );
assert( be != NULL );
oi = op->o_bd->bd_info->bi_private;
bi = be->bd_info;
oi = bi->bi_private;
on = oi->oi_list;
for ( ; on; on = on->on_next ) {
......
......@@ -120,6 +120,8 @@ cr_insert(
struct cindexrec *cir;
char **names;
assert( scr != NULL );
if ( scr->scr_oid ) {
cir = (struct cindexrec *)
ch_calloc( 1, sizeof(struct cindexrec) );
......@@ -127,9 +129,6 @@ cr_insert(
cir->cir_name.bv_len = strlen( scr->scr_oid );
cir->cir_cr = scr;
assert( cir->cir_name.bv_val != NULL );
assert( cir->cir_cr != NULL );
if ( avl_insert( &cr_index, (caddr_t) cir,
cr_index_cmp, avl_dup_error ) )
{
......@@ -150,9 +149,6 @@ cr_insert(
cir->cir_name.bv_len = strlen( *names );
cir->cir_cr = scr;
assert( cir->cir_name.bv_val != NULL );
assert( cir->cir_cr != NULL );
if ( avl_insert( &cr_index, (caddr_t) cir,
cr_index_cmp, avl_dup_error ) )
{
......
......@@ -703,11 +703,10 @@ dnPrettyNormal(
struct berval *normal,
void *ctx)
{
Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 );
assert( val != NULL );
assert( pretty != NULL );
assert( normal != NULL );
Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 );
if ( val->bv_len == 0 ) {
ber_dupbv_x( pretty, val, ctx );
......@@ -1169,11 +1168,13 @@ dnIsSuffix(
const struct berval *dn,
const struct berval *suffix )
{
int d = dn->bv_len - suffix->bv_len;
int d;
assert( dn != NULL );
assert( suffix != NULL );
d = dn->bv_len - suffix->bv_len;
/* empty suffix matches any dn */
if ( suffix->bv_len == 0 ) {
return 1;
......
......@@ -637,6 +637,8 @@ oc_insert(
assert( oc_bvfind( &oir->oir_name ) != NULL );
}
assert( soc != NULL );
if ( (names = soc->soc_names) ) {
while ( *names ) {
oir = (struct oindexrec *)
......@@ -645,9 +647,6 @@ oc_insert(
oir->oir_name.bv_len = strlen( *names );
oir->oir_oc = soc;
assert( oir->oir_name.bv_val != NULL );
assert( oir->oir_oc != NULL );
if ( avl_insert( &oc_index, (caddr_t) oir,
oc_index_cmp, avl_dup_error ) )
{
......
......@@ -591,13 +591,15 @@ static int
check_password_quality( struct berval *cred, PassPolicy *pp, LDAPPasswordPolicyError *err, Entry *e, char **txt )
{
int rc = LDAP_SUCCESS, ok = LDAP_SUCCESS;
char *ptr = cred->bv_val;
char *ptr;
struct berval sch;
assert( cred != NULL );
assert( pp != NULL );
assert( txt != NULL );
ptr = cred->bv_val;
*txt = NULL;
if ((cred->bv_len == 0) || (pp->pwdMinLength > cred->bv_len)) {
......
......@@ -469,7 +469,7 @@ ordered_value_pretty(
struct berval *out,
void *ctx )
{
struct berval bv = *val,
struct berval bv,
idx = BER_BVNULL;
int rc;
......@@ -478,6 +478,8 @@ ordered_value_pretty(
assert( val != NULL );
assert( out != NULL );
bv = *val;
if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
/* Skip past the assertion index */
......@@ -538,7 +540,7 @@ ordered_value_normalize(
struct berval *normalized,
void *ctx )
{
struct berval bv = *val,
struct berval bv,
idx = BER_BVNULL;
int rc;
......@@ -547,6 +549,8 @@ ordered_value_normalize(
assert( val != NULL );
assert( normalized != NULL );
bv = *val;
if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
/* Skip past the assertion index */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment