andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From cd5fc30dd7eae2812d847e142a95f1f44b39d5e9 Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Tue, 11 Mar 2014 16:44:34 -0400
dc8c34
Subject: [PATCH 180/225] Ticket 47740 - Coverity Fixes (Mark - part 1)
dc8c34
dc8c34
Fixed these issues:
dc8c34
dc8c34
12510 - resource leak in lib/libutil/certmap.c
dc8c34
12509 - resource leak in ldap/servers/plugins/chainingdb/cb_bind.c
dc8c34
12508 - resource leak in ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
12507 - resource leak in ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
12506 - resource leak in ldap/servers/plugins/chainingdb/cb_config.c
dc8c34
12505 - resource leak in ldap/servers/plugins/posix-winsync/posix-winsync.c
dc8c34
12500 - resource leak in ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47740
dc8c34
dc8c34
Reviewed by: nhosoi(Thanks!)
dc8c34
(cherry picked from commit d3ed247b7ed59eac8776ea9e73ee21ec8bcd2011)
dc8c34
(cherry picked from commit ea59c06fdb40f3fe7bd90742dfb9a49a46c27334)
dc8c34
---
dc8c34
 ldap/servers/plugins/chainingdb/cb_bind.c          |  5 +-
dc8c34
 ldap/servers/plugins/chainingdb/cb_config.c        | 70 ++++++++++------------
dc8c34
 ldap/servers/plugins/chainingdb/cb_instance.c      | 61 +++++++++----------
dc8c34
 ldap/servers/plugins/posix-winsync/posix-winsync.c |  9 +--
dc8c34
 .../plugins/replication/repl5_replica_config.c     |  2 +
dc8c34
 lib/ldaputil/certmap.c                             |  5 +-
dc8c34
 6 files changed, 75 insertions(+), 77 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_bind.c b/ldap/servers/plugins/chainingdb/cb_bind.c
dc8c34
index 18e526a..7c22931 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_bind.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_bind.c
dc8c34
@@ -307,6 +307,7 @@ chainingdb_bind( Slapi_PBlock *pb )
dc8c34
 		rc = status;
dc8c34
 		allocated_errmsg = 1;
dc8c34
 	} else if ( LDAP_USER_CANCELLED != rc ) {
dc8c34
+		slapi_ch_free_string(&errmsg);
dc8c34
 		errmsg = ldap_err2string( rc );
dc8c34
 		if (rc == LDAP_TIMEOUT) {
dc8c34
 			cb_ping_farm(cb,NULL,0);
dc8c34
@@ -332,8 +333,8 @@ chainingdb_bind( Slapi_PBlock *pb )
dc8c34
 		ldap_controls_free( resctrls );
dc8c34
 	}
dc8c34
 	slapi_ch_free((void **)& matcheddn );
dc8c34
-	if ( allocated_errmsg && errmsg != NULL ) {
dc8c34
-		slapi_ch_free((void **)& errmsg );
dc8c34
+	if ( allocated_errmsg ) {
dc8c34
+		slapi_ch_free_string(&errmsg);
dc8c34
 	}
dc8c34
 
dc8c34
 	slapi_sdn_free(&mysdn);
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_config.c b/ldap/servers/plugins/chainingdb/cb_config.c
dc8c34
index 717ea3c..d05470c 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_config.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_config.c
dc8c34
@@ -487,45 +487,39 @@ cb_config_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entr
dc8c34
 
dc8c34
                         slapi_rwlock_unlock(cb->config.rwl_config_lock);
dc8c34
 		} else
dc8c34
-		if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_CHAINABLE_COMPONENTS )) {
dc8c34
-                        char * config_attr_value;
dc8c34
-                        int done=0;
dc8c34
-
dc8c34
-                        slapi_rwlock_wrlock(cb->config.rwl_config_lock);
dc8c34
-
dc8c34
-                        for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
dc8c34
-                                config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
dc8c34
-                                if (SLAPI_IS_MOD_REPLACE(mods[i]->mod_op)) {
dc8c34
-                                        if (!done) {
dc8c34
-                                                charray_free(cb->config.chainable_components);
dc8c34
-                                                cb->config.chainable_components=NULL;
dc8c34
-                                                done=1;
dc8c34
-                                        }
dc8c34
-                                        charray_add(&cb->config.chainable_components,
dc8c34
-                                                slapi_dn_normalize(slapi_ch_strdup(config_attr_value)
dc8c34
-));
dc8c34
-                                } else
dc8c34
-                                if (SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
dc8c34
-                                        charray_add(&cb->config.chainable_components,
dc8c34
-                                                slapi_dn_normalize(slapi_ch_strdup(config_attr_value)
dc8c34
-));
dc8c34
-                                } else
dc8c34
-                                if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op)) {
dc8c34
-                                        charray_remove(cb->config.chainable_components,
dc8c34
-                                                slapi_dn_normalize(slapi_ch_strdup(config_attr_value)
dc8c34
-),
dc8c34
-												0 /* freeit */);
dc8c34
-                                }
dc8c34
-                        }
dc8c34
-                        if (NULL == mods[i]->mod_bvalues) {
dc8c34
-                                charray_free(cb->config.chainable_components);
dc8c34
-                                cb->config.chainable_components=NULL;
dc8c34
-                        }
dc8c34
-
dc8c34
-                        slapi_rwlock_unlock(cb->config.rwl_config_lock);
dc8c34
-                }
dc8c34
-
dc8c34
+			if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_CHAINABLE_COMPONENTS )) {
dc8c34
+				char *config_attr_value;
dc8c34
+				char *attr_val;
dc8c34
+				int done=0;
dc8c34
+
dc8c34
+				slapi_rwlock_wrlock(cb->config.rwl_config_lock);
dc8c34
+
dc8c34
+				for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
dc8c34
+					config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
dc8c34
+					if (SLAPI_IS_MOD_REPLACE(mods[i]->mod_op)) {
dc8c34
+						if (!done) {
dc8c34
+							charray_free(cb->config.chainable_components);
dc8c34
+							cb->config.chainable_components=NULL;
dc8c34
+							done=1;
dc8c34
+						}
dc8c34
+						charray_add(&cb->config.chainable_components,
dc8c34
+						slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
dc8c34
+					} else if (SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
dc8c34
+						charray_add(&cb->config.chainable_components,
dc8c34
+						slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
dc8c34
+					} else if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op)) {
dc8c34
+						attr_val = slapi_dn_normalize(slapi_ch_strdup(config_attr_value));
dc8c34
+						charray_remove(cb->config.chainable_components, attr_val, 0 /* freeit */);
dc8c34
+						slapi_ch_free_string(&attr_val);
dc8c34
+					}
dc8c34
+				}
dc8c34
+				if (NULL == mods[i]->mod_bvalues) {
dc8c34
+					charray_free(cb->config.chainable_components);
dc8c34
+					cb->config.chainable_components=NULL;
dc8c34
+				}
dc8c34
 
dc8c34
+				slapi_rwlock_unlock(cb->config.rwl_config_lock);
dc8c34
+		}
dc8c34
 	}
dc8c34
 	*returncode=LDAP_SUCCESS;
dc8c34
 	return SLAPI_DSE_CALLBACK_OK;
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_instance.c b/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
index 95781b5..ce7675b 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
@@ -417,43 +417,40 @@ int cb_instance_modify_config_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                         continue;
dc8c34
 		} 
dc8c34
 		if ( !strcasecmp ( attr_name, CB_CONFIG_CHAINING_COMPONENTS )) {
dc8c34
-               		char * config_attr_value;
dc8c34
-                       	int done=0;
dc8c34
+			char *config_attr_value;
dc8c34
+			char *attr_val;
dc8c34
+			int done=0;
dc8c34
 			int j;
dc8c34
 
dc8c34
-        		slapi_rwlock_wrlock(inst->rwl_config_lock);
dc8c34
-                       	for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
dc8c34
-                               	config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
dc8c34
-                               	if (SLAPI_IS_MOD_REPLACE(mods[i]->mod_op)) {
dc8c34
-                                       	if (!done) {
dc8c34
-                                               	charray_free(inst->chaining_components);
dc8c34
-                                               	inst->chaining_components=NULL;
dc8c34
-                                               	done=1;
dc8c34
-                                       	}
dc8c34
+			slapi_rwlock_wrlock(inst->rwl_config_lock);
dc8c34
+			for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
dc8c34
+				config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
dc8c34
+				if (SLAPI_IS_MOD_REPLACE(mods[i]->mod_op)) {
dc8c34
+					if (!done) {
dc8c34
+						charray_free(inst->chaining_components);
dc8c34
+						inst->chaining_components=NULL;
dc8c34
+						done=1;
dc8c34
+					}
dc8c34
 					/* XXXSD assume dns */
dc8c34
-                                       	charray_add(&inst->chaining_components,
dc8c34
-                                               	slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
dc8c34
-                               	} else
dc8c34
-                               	if (SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
dc8c34
-                                       	charray_add(&inst->chaining_components,
dc8c34
-                                               	slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
dc8c34
-                               	} else
dc8c34
-                               	if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op)) {
dc8c34
-                                       	charray_remove(inst->chaining_components,
dc8c34
-                                               	slapi_dn_normalize(slapi_ch_strdup(config_attr_value)),
dc8c34
-												0 /* freeit */);
dc8c34
-                               	}
dc8c34
-                       	}
dc8c34
-                       	if (NULL == mods[i]->mod_bvalues) {
dc8c34
-                               	charray_free(inst->chaining_components);
dc8c34
-                               	inst->chaining_components=NULL;
dc8c34
-                       	}
dc8c34
-        		slapi_rwlock_unlock(inst->rwl_config_lock);
dc8c34
-                        continue;
dc8c34
+					charray_add(&inst->chaining_components,
dc8c34
+									slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
dc8c34
+				} else if (SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
dc8c34
+					charray_add(&inst->chaining_components,
dc8c34
+								slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
dc8c34
+				} else if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op)) {
dc8c34
+					attr_val = slapi_dn_normalize(slapi_ch_strdup(config_attr_value));
dc8c34
+					charray_remove(inst->chaining_components,attr_val, 0 /* freeit */);
dc8c34
+					slapi_ch_free_string(&attr_val);
dc8c34
+				}
dc8c34
+			}
dc8c34
+			if (NULL == mods[i]->mod_bvalues) {
dc8c34
+				charray_free(inst->chaining_components);
dc8c34
+				inst->chaining_components=NULL;
dc8c34
+			}
dc8c34
+			slapi_rwlock_unlock(inst->rwl_config_lock);
dc8c34
+			continue;
dc8c34
 		} 
dc8c34
 
dc8c34
-
dc8c34
-
dc8c34
 		if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op) || 
dc8c34
                         SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
dc8c34
 
dc8c34
diff --git a/ldap/servers/plugins/posix-winsync/posix-winsync.c b/ldap/servers/plugins/posix-winsync/posix-winsync.c
dc8c34
index 92a3a79..0919159 100644
dc8c34
--- a/ldap/servers/plugins/posix-winsync/posix-winsync.c
dc8c34
+++ b/ldap/servers/plugins/posix-winsync/posix-winsync.c
dc8c34
@@ -1373,21 +1373,22 @@ posix_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slap
dc8c34
         int rc = 0;
dc8c34
         char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
dc8c34
                                           posix_winsync_plugin_name, MEMBEROFTASK);
dc8c34
-        slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
dc8c34
-                        "--> posix_winsync_end_update_cb, create task %s\n", dn);
dc8c34
+
dc8c34
         if (NULL == dn) {
dc8c34
             slapi_pblock_destroy(pb);
dc8c34
+            slapi_entry_free(e_task);
dc8c34
             slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
dc8c34
                             "posix_winsync_end_update_cb: "
dc8c34
                                 "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
dc8c34
                             posix_winsync_plugin_name, MEMBEROFTASK);
dc8c34
             return;
dc8c34
         }
dc8c34
-
dc8c34
+        slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
dc8c34
+                        "--> posix_winsync_end_update_cb, create task %s\n", dn);
dc8c34
         slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
dc8c34
                         "--> posix_winsync_end_update_cb, init'ing task\n");
dc8c34
 
dc8c34
-        slapi_entry_init(e_task, slapi_ch_strdup(dn), NULL);
dc8c34
+        slapi_entry_init(e_task, dn, NULL);
dc8c34
         slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
dc8c34
         slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
dc8c34
         slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
dc8c34
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
index 9a0b190..d020ffb 100644
dc8c34
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
@@ -416,10 +416,12 @@ replica_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry*
dc8c34
                 }
dc8c34
                 else if (strcasecmp (config_attr, attr_replicaType) == 0)
dc8c34
 			    {
dc8c34
+                	slapi_ch_free_string(&new_repl_type);
dc8c34
 					new_repl_type = slapi_ch_strdup(config_attr_value);
dc8c34
                 }
dc8c34
                 else if (strcasecmp (config_attr, attr_replicaId) == 0)
dc8c34
 			    {
dc8c34
+                	slapi_ch_free_string(&new_repl_id);
dc8c34
 					new_repl_id = slapi_ch_strdup(config_attr_value);
dc8c34
                 }
dc8c34
                 else if (strcasecmp (config_attr, attr_flags) == 0)
dc8c34
diff --git a/lib/ldaputil/certmap.c b/lib/ldaputil/certmap.c
dc8c34
index f3da425..e27633c 100644
dc8c34
--- a/lib/ldaputil/certmap.c
dc8c34
+++ b/lib/ldaputil/certmap.c
dc8c34
@@ -745,7 +745,10 @@ static int ldapu_cert_searchfn_default (void *cert, LDAP *ld,
dc8c34
 	len = strlen(certmap_info->searchAttr) + strlen(subjectDN) +
dc8c34
 	    strlen("=") + 1;
dc8c34
 	certFilter = (char *)ldapu_malloc(len * sizeof(char));
dc8c34
-	if (!certFilter) return LDAPU_ERR_OUT_OF_MEMORY;
dc8c34
+	if (!certFilter){
dc8c34
+		free(subjectDN);
dc8c34
+		return LDAPU_ERR_OUT_OF_MEMORY;
dc8c34
+	}
dc8c34
 	sprintf(certFilter, "%s=%s", certmap_info->searchAttr, subjectDN);
dc8c34
 	free(subjectDN);
dc8c34
 	if ( ldapu_strcasecmp(basedn, "") ) {
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34