Преглед изворни кода

Coverity Fixes

    Fixed:

    13142 - Unused pointer in config_set-onoff()
    13141 - Uninitialized pointer in idl_new_range_fetch()
    13140 - Dereference before NULL check in slapi_attr_is_dn_syntax()
    13139 - Dereference after NULL check in slapi_attr_value_normalize_ext()
    13138 - Dereference after NULL check in idl_new_range_fetch()

    Also cleaned up some compiler warnings.

    Reviewed by: richm(Thanks!)
Mark Reynolds пре 12 година
родитељ
комит
a550a91e5c

+ 1 - 1
ldap/servers/slapd/attrsyntax.c

@@ -813,7 +813,7 @@ slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr)
 	const char *syntaxoid = NULL;
 	int dn_syntax = 0; /* not DN, by default */
 
-	if ( attr->a_plugin == NULL ) { 
+	if (attr && attr->a_plugin == NULL) {
  	    slapi_attr_init_syntax (attr);
  	}
 	if (attr && attr->a_plugin) { /* If not set, there is no way to get the info */

+ 6 - 3
ldap/servers/slapd/back-ldbm/idl_new.c

@@ -400,8 +400,8 @@ idl_new_range_fetch(
     int idl_rc = 0;
     DBC *cursor = NULL;
     IDList *idl = NULL;
-    DBT cur_key;
-    DBT data;
+    DBT cur_key = {0};
+    DBT data = {0};
     ID id = 0;
     size_t count = 0;
 #ifdef DB_USE_BULK_FETCH
@@ -420,7 +420,10 @@ idl_new_range_fetch(
         *flag_err = 0;
         return NULL;
     }
-
+    if(upperkey == NULL){
+        LDAPDebug(LDAP_DEBUG_ANY, "idl_new_range_fetch: upperkey is NULL\n",0,0,0);
+        return ret;
+    }
     dblayer_txn_init(li, &s_txn);
     if (txn) {
         dblayer_read_txn_begin(be, txn, &s_txn);

+ 5 - 3
ldap/servers/slapd/libglobs.c

@@ -3111,12 +3111,15 @@ config_set_onoff ( const char *attrname, char *value, int *configvalue,
 {
   int retVal = LDAP_SUCCESS;
   slapi_onoff_t newval = -1;
+#ifndef ATOMIC_GETSET_ONOFF
   slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+#endif 
   
   if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
 	return LDAP_OPERATIONS_ERROR;
   }
   
+  CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig);
   if ( strcasecmp ( value, "on" ) != 0 &&
 	   strcasecmp ( value, "off") != 0 && 
 	   /* initializing the value */
@@ -3132,8 +3135,6 @@ config_set_onoff ( const char *attrname, char *value, int *configvalue,
 	/* we can return now if we aren't applying the changes */
 	return retVal;
   }
-
-  CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig);
   
   if ( strcasecmp ( value, "on" ) == 0 ) {
 	newval = LDAP_ON;
@@ -3148,7 +3149,8 @@ config_set_onoff ( const char *attrname, char *value, int *configvalue,
 #else
   *configvalue = newval;
 #endif
-  CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig);
+  CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig); 
+
   return retVal;
 }
 			 

+ 10 - 6
ldap/servers/slapd/plugin_syntax.c

@@ -136,7 +136,7 @@ plugin_call_syntax_filter_ava_sv(
 
 	if ( ( a->a_mr_eq_plugin == NULL ) && ( a->a_mr_ord_plugin == NULL ) && ( a->a_plugin == NULL ) ) {
 		/* could be lazy plugin initialization, get it now */
-		Slapi_Attr *t = a;
+		Slapi_Attr *t = (Slapi_Attr *)a;
 		slapi_attr_init_syntax(t);
 	}
 
@@ -625,7 +625,7 @@ slapi_attr_values2keys_sv_pb(
 	    0, 0, 0 );
 	if ( ( sattr->a_plugin == NULL ) ) {
 		/* could be lazy plugin initialization, get it now */
-		slapi_attr_init_syntax(sattr);
+		slapi_attr_init_syntax((Slapi_Attr *)sattr);
 	}
 
 	switch (ftype) {
@@ -797,7 +797,7 @@ slapi_attr_assertion2keys_ava_sv(
 	    "=> slapi_attr_assertion2keys_ava_sv\n", 0, 0, 0 );
 	if ( ( sattr->a_plugin == NULL ) ) {
 		/* could be lazy plugin initialization, get it now */
-		slapi_attr_init_syntax(sattr);
+		slapi_attr_init_syntax((Slapi_Attr *)sattr);
 	}
 
 	switch (ftype) {
@@ -917,7 +917,7 @@ slapi_attr_assertion2keys_sub_sv(
 	    "=> slapi_attr_assertion2keys_sub_sv\n", 0, 0, 0 );
 	if ( ( sattr->a_plugin == NULL ) ) {
 		/* could be lazy plugin initialization, get it now */
-		slapi_attr_init_syntax(sattr);
+		slapi_attr_init_syntax((Slapi_Attr *)sattr);
 	}
 
 	if (sattr->a_mr_sub_plugin) {
@@ -974,10 +974,14 @@ slapi_attr_value_normalize_ext(
 
 	if (!sattr) {
 		sattr = slapi_attr_init(&myattr, type);
+		if(!sattr){
+			attr_done(&myattr);
+			return;
+		}
 	}
 	if ( ( sattr->a_plugin == NULL ) ) {
 		/* could be lazy plugin initialization, get it now */
-		slapi_attr_init_syntax(sattr);
+		slapi_attr_init_syntax((Slapi_Attr *)sattr);
 	}
 
 	/* use the filter type to determine which matching rule to use */
@@ -1002,7 +1006,7 @@ slapi_attr_value_normalize_ext(
 		break;
 	}
 
-	if (!norm_fn) {
+	if (!norm_fn && sattr->a_plugin) {
 		/* no matching rule specific normalizer specified - use syntax default */
 		norm_fn = sattr->a_plugin->plg_syntax_normalize;
 	}