Browse Source

610281 - fix coverity Defect Type: Control flow issues

https://bugzilla.redhat.com/show_bug.cgi?id=610281

11841 DEADCODE Triaged Unassigned Bug Minor Fix Required
sasl_map_new_private() ds/ldap/servers/slapd/sasl_map.c

Comment:
This new_lock NULL checking is not needed.
  On this path, the condition "NULL == new_lock" cannot be true.
   97   if (NULL == new_lock) {
  Execution cannot reach this statement "slapi_ch_free((void**)new_p...".
   98       slapi_ch_free((void**)new_priv);
   99       return NULL;
  100   }

11842 DEADCODE Triaged Unassigned Bug Minor Fix Required
sasl_map_insert_list_entry() ds/ldap/servers/slapd/sasl_map.c

Comment:
In sasl_map_insert_list_entry, /* Check to see if it's here
already */ was not implemented.  The variable ishere pointed
by coverity should have been prepared for the purpose.
Implementing a helper function sasl_map_cmp_data.
Noriko Hosoi 15 years ago
parent
commit
f502808c02
1 changed files with 47 additions and 6 deletions
  1. 47 6
      ldap/servers/slapd/sasl_map.c

+ 47 - 6
ldap/servers/slapd/sasl_map.c

@@ -94,10 +94,6 @@ sasl_map_private *sasl_map_new_private()
 	}
 	new_priv = (sasl_map_private *)slapi_ch_calloc(1,sizeof(sasl_map_private));
 	new_priv->lock = new_lock;
-	if (NULL == new_lock) {
-		slapi_ch_free((void**)new_priv);
-		return NULL;
-	}
 	return new_priv;
 }
 
@@ -171,17 +167,62 @@ sasl_map_remove_list_entry(sasl_map_private *priv, char *removeme)
 	return ret;
 }
 
+static int 
+sasl_map_cmp_data(sasl_map_data *dp0, sasl_map_data *dp1)
+{
+	int rc = 0;
+	if (NULL == dp0) {
+		if (NULL == dp1) {
+			return 0;
+		} else {
+			return -1;
+		}
+	} else {
+		if (NULL == dp1) {
+			return 1;
+		}
+	}
+
+	rc = PL_strcmp(dp0->name, dp1->name);
+	if (0 != rc) {
+		/* did not match */
+		return rc;
+	}
+	rc = PL_strcmp(dp0->regular_expression, dp1->regular_expression);
+	if (0 != rc) {
+		/* did not match */
+		return rc;
+	}
+	rc = PL_strcmp(dp0->template_base_dn, dp1->template_base_dn);
+	if (0 != rc) {
+		/* did not match */
+		return rc;
+	}
+	rc = PL_strcmp(dp0->template_search_filter, dp1->template_search_filter);
+	return rc;
+}
+
 static int 
 sasl_map_insert_list_entry(sasl_map_private *priv, sasl_map_data *dp)
 {
 	int ret = 0;
 	int ishere = 0;
 	sasl_map_data *current = NULL;
+	if (NULL == dp) {
+		return ret;
+	}
 	PR_Lock(priv->lock);
 	/* Check to see if it's here already */
 	current = priv->map_data_list;
-	while (current && current->next) {
-		current = current->next;
+	while (current) {
+		if (0 == sasl_map_cmp_data(current, dp)) {
+			ishere = 1;
+		}
+		if (current->next) {
+			current = current->next;
+		} else {
+			break;
+		}
 	}
 	if (ishere) {
 		return -1;