andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From d02be8587d411b75e8b72c5830528641007cc15a Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Wed, 12 Mar 2014 14:38:50 -0400
dc8c34
Subject: [PATCH 182/225] Ticket 47740 - Fix coverity issues - part 3
dc8c34
dc8c34
12504 - resource leak - /ldap/servers/slapd/back-ldbm/import-threads.c
dc8c34
12499 - resource leak - /ldap/servers/slapd/passwd_extop.c
dc8c34
12497 - resource leak - /ldap/servers/slapd/mapping_tree.c
dc8c34
12496 - resource leak - /ldap/servers/slapd/mapping_tree.c
dc8c34
12495 - resource leak - /ldap/servers/plugins/replication/legacy_consumer.c
dc8c34
12493 - resource leak - /ldap/servers/slapd/tools/rsearch/sdattable.c
dc8c34
12492 - resource leak - /ldap/servers/slapd/tools/pwenc.c
dc8c34
12491 - resource leak - /ldap/servers/slapd/tools/mmldif.c
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47740
dc8c34
dc8c34
Reviewed by: rmeggins(Thanks!)
dc8c34
(cherry picked from commit ff78177452f1ac3da6039640815cc2eaf55b0b40)
dc8c34
(cherry picked from commit 2b9788b7d282b055b6f1945eb3f3b5c784d779fc)
dc8c34
(cherry picked from commit fd8668bcf47935a4fb90d782badf6c8bf07f6c94)
dc8c34
---
dc8c34
 ldap/servers/plugins/replication/legacy_consumer.c | 10 ++--
dc8c34
 ldap/servers/slapd/back-ldbm/import-threads.c      |  1 +
dc8c34
 ldap/servers/slapd/mapping_tree.c                  | 16 ++++++
dc8c34
 ldap/servers/slapd/passwd_extop.c                  |  4 +-
dc8c34
 ldap/servers/slapd/tools/mmldif.c                  |  2 +
dc8c34
 ldap/servers/slapd/tools/pwenc.c                   |  4 +-
dc8c34
 ldap/servers/slapd/tools/rsearch/sdattable.c       | 58 ++++++++++++++--------
dc8c34
 7 files changed, 65 insertions(+), 30 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/replication/legacy_consumer.c b/ldap/servers/plugins/replication/legacy_consumer.c
dc8c34
index 2440ce7..aa5a9b5 100644
dc8c34
--- a/ldap/servers/plugins/replication/legacy_consumer.c
dc8c34
+++ b/ldap/servers/plugins/replication/legacy_consumer.c
dc8c34
@@ -371,11 +371,12 @@ legacy_consumer_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi
dc8c34
                 {
dc8c34
                     if (mod_type == LDAP_MOD_REPLACE)
dc8c34
                     {
dc8c34
+                        slapi_ch_free_string(&legacy_consumer_replicationpw);
dc8c34
                         legacy_consumer_replicationpw = config_copy_strval(config_attr_value);
dc8c34
                     }
dc8c34
                     else if (mod_type == LDAP_MOD_DELETE)
dc8c34
                     {
dc8c34
-                        legacy_consumer_replicationpw = NULL;
dc8c34
+                        slapi_ch_free_string(&legacy_consumer_replicationpw);
dc8c34
                     }
dc8c34
                     else if (mod_type == LDAP_MOD_ADD)
dc8c34
                     {
dc8c34
@@ -387,6 +388,7 @@ legacy_consumer_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi
dc8c34
                         }
dc8c34
                         else
dc8c34
                         {
dc8c34
+                            slapi_ch_free_string(&legacy_consumer_replicationpw);
dc8c34
                             legacy_consumer_replicationpw = config_copy_strval(config_attr_value);
dc8c34
                         }
dc8c34
                     }
dc8c34
@@ -419,11 +421,8 @@ legacy_consumer_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* en
dc8c34
 	slapi_rwlock_wrlock (legacy_consumer_config_lock);
dc8c34
     if (legacy_consumer_replicationdn)
dc8c34
         slapi_sdn_free (&legacy_consumer_replicationdn);
dc8c34
-    if (legacy_consumer_replicationpw)
dc8c34
-        slapi_ch_free ((void**)&legacy_consumer_replicationpw);
dc8c34
-
dc8c34
+    slapi_ch_free_string(&legacy_consumer_replicationpw);
dc8c34
 	legacy_consumer_replicationdn = NULL;
dc8c34
-    legacy_consumer_replicationpw = NULL;
dc8c34
 	slapi_rwlock_unlock (legacy_consumer_config_lock);
dc8c34
 
dc8c34
 	*returncode = LDAP_SUCCESS;
dc8c34
@@ -446,6 +445,7 @@ legacy_consumer_extract_config(Slapi_Entry* entry, char *returntext)
dc8c34
 	    legacy_consumer_replicationdn = slapi_sdn_new_dn_passin (arg);
dc8c34
 
dc8c34
     arg= slapi_entry_attr_get_charptr(entry,CONFIG_LEGACY_REPLICATIONPW_ATTRIBUTE);
dc8c34
+    slapi_ch_free_string(&legacy_consumer_replicationpw);
dc8c34
     legacy_consumer_replicationpw = arg;
dc8c34
 
dc8c34
 	slapi_rwlock_unlock (legacy_consumer_config_lock);
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c
dc8c34
index c7d3444..d30936e 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/import-threads.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/import-threads.c
dc8c34
@@ -2256,6 +2256,7 @@ import_foreman(void *param)
dc8c34
                                             "of the duplicated entry %s; "
dc8c34
                                             "Entry ID: %d", 
dc8c34
                                             orig_dn, fi->entry->ep_id);
dc8c34
+                    slapi_ch_free_string(&orig_dn);
dc8c34
                     goto cont;
dc8c34
                 }
dc8c34
                 new_entrydn = slapi_attr_new();
dc8c34
diff --git a/ldap/servers/slapd/mapping_tree.c b/ldap/servers/slapd/mapping_tree.c
dc8c34
index 19c5708..12d9205 100644
dc8c34
--- a/ldap/servers/slapd/mapping_tree.c
dc8c34
+++ b/ldap/servers/slapd/mapping_tree.c
dc8c34
@@ -1110,6 +1110,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                           "Error: could not find parent for %s\n",
dc8c34
                           slapi_entry_get_dn(entryAfter), 0, 0);
dc8c34
                     slapi_sdn_free(&subtree);
dc8c34
+                    slapi_ch_free_string(&plugin_fct);
dc8c34
+                    slapi_ch_free_string(&plugin_lib);
dc8c34
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
dc8c34
                     return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
                 }
dc8c34
@@ -1148,6 +1150,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
             {
dc8c34
                 free_mapping_tree_node_arrays(&backends, &be_names, &be_states, &be_list_count);
dc8c34
                 slapi_sdn_free(&subtree);
dc8c34
+                slapi_ch_free_string(&plugin_fct);
dc8c34
+                slapi_ch_free_string(&plugin_lib);
dc8c34
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
dc8c34
                 return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
             }
dc8c34
@@ -1161,6 +1165,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                 mtn_unlock();
dc8c34
                 free_mapping_tree_node_arrays(&backends, &be_names, &be_states, &be_list_count);
dc8c34
                 slapi_sdn_free(&subtree);
dc8c34
+                slapi_ch_free_string(&plugin_fct);
dc8c34
+                slapi_ch_free_string(&plugin_lib);
dc8c34
                 return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
             }
dc8c34
 
dc8c34
@@ -1189,12 +1195,16 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                 PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "must use replace operation to change state\n");
dc8c34
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
dc8c34
                 slapi_sdn_free(&subtree);
dc8c34
+                slapi_ch_free_string(&plugin_fct);
dc8c34
+                slapi_ch_free_string(&plugin_lib);
dc8c34
                 return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
             }
dc8c34
             if ((mods[i]->mod_bvalues == NULL) || (mods[i]->mod_bvalues[0] == NULL))
dc8c34
             {
dc8c34
                 slapi_sdn_free(&subtree);
dc8c34
                 *returncode = LDAP_OPERATIONS_ERROR;
dc8c34
+                slapi_ch_free_string(&plugin_fct);
dc8c34
+                slapi_ch_free_string(&plugin_lib);
dc8c34
                 return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
             }
dc8c34
 
dc8c34
@@ -1208,6 +1218,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                 {
dc8c34
                     PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "need to set nsslapd-backend before moving to backend state\n");
dc8c34
                     slapi_sdn_free(&subtree);
dc8c34
+                    slapi_ch_free_string(&plugin_fct);
dc8c34
+                    slapi_ch_free_string(&plugin_lib);
dc8c34
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
dc8c34
                     return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
                 }
dc8c34
@@ -1220,6 +1232,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                 {
dc8c34
                     PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "need to set nsslapd-referral before moving to referral state\n");
dc8c34
                     slapi_sdn_free(&subtree);
dc8c34
+                    slapi_ch_free_string(&plugin_fct);
dc8c34
+                    slapi_ch_free_string(&plugin_lib);
dc8c34
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
dc8c34
                     return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
                 }
dc8c34
@@ -1258,6 +1272,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
dc8c34
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
dc8c34
                     mtn_unlock();
dc8c34
                     slapi_sdn_free(&subtree);
dc8c34
+                    slapi_ch_free_string(&plugin_fct);
dc8c34
+                    slapi_ch_free_string(&plugin_lib);
dc8c34
                     return SLAPI_DSE_CALLBACK_ERROR;
dc8c34
                 }
dc8c34
 
dc8c34
diff --git a/ldap/servers/slapd/passwd_extop.c b/ldap/servers/slapd/passwd_extop.c
dc8c34
index 4aebee3..9ad470f 100644
dc8c34
--- a/ldap/servers/slapd/passwd_extop.c
dc8c34
+++ b/ldap/servers/slapd/passwd_extop.c
dc8c34
@@ -905,7 +905,6 @@ static char *passwd_name_list[] = {
dc8c34
 int passwd_modify_init( Slapi_PBlock *pb )
dc8c34
 {
dc8c34
 	char	**argv;
dc8c34
-	char	*oid;
dc8c34
 
dc8c34
 	/* Get the arguments appended to the plugin extendedop directive. The first argument 
dc8c34
 	 * (after the standard arguments for the directive) should contain the OID of the
dc8c34
@@ -924,9 +923,8 @@ int passwd_modify_init( Slapi_PBlock *pb )
dc8c34
 				 "OID is missing or is not %s\n", EXTOP_PASSWD_OID );
dc8c34
 		return( -1 );
dc8c34
 	} else {
dc8c34
-		oid = slapi_ch_strdup( argv[0] );
dc8c34
 		slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_modify_init", 
dc8c34
-				 "Registering plug-in for Password Modify extended op %s.\n", oid );
dc8c34
+				 "Registering plug-in for Password Modify extended op %s.\n", argv[0] /* oid */);
dc8c34
 	}
dc8c34
 
dc8c34
 	/* Register the plug-in function as an extended operation
dc8c34
diff --git a/ldap/servers/slapd/tools/mmldif.c b/ldap/servers/slapd/tools/mmldif.c
dc8c34
index 1f01976..4213e65 100644
dc8c34
--- a/ldap/servers/slapd/tools/mmldif.c
dc8c34
+++ b/ldap/servers/slapd/tools/mmldif.c
dc8c34
@@ -659,6 +659,7 @@ int mm_init(int argc, char * argv[])
dc8c34
             slapd_ldap_debug = 65535;
dc8c34
             break;
dc8c34
         case 'o':
dc8c34
+            if(ofn) free (ofn);
dc8c34
             ofn = strdup(optarg);
dc8c34
             break;
dc8c34
         case 'h':
dc8c34
@@ -677,6 +678,7 @@ int mm_init(int argc, char * argv[])
dc8c34
         ofp = fopen(ofn, "w");
dc8c34
         if (ofp == NULL) {
dc8c34
             perror(ofn);
dc8c34
+            free(ofn);
dc8c34
             return -1;
dc8c34
         }
dc8c34
         free(ofn);
dc8c34
diff --git a/ldap/servers/slapd/tools/pwenc.c b/ldap/servers/slapd/tools/pwenc.c
dc8c34
index 221398c..34cfe1b 100644
dc8c34
--- a/ldap/servers/slapd/tools/pwenc.c
dc8c34
+++ b/ldap/servers/slapd/tools/pwenc.c
dc8c34
@@ -140,8 +140,10 @@ init_config(char *configdir)
dc8c34
 
dc8c34
     abs_configdir = rel2abspath( configdir );
dc8c34
     if ( config_set_configdir( "configdir (-D)", abs_configdir,
dc8c34
-                               errorbuf, 1) != LDAP_SUCCESS ) {
dc8c34
+                               errorbuf, 1) != LDAP_SUCCESS )
dc8c34
+    {
dc8c34
         fprintf( stderr, "%s\n", errorbuf );
dc8c34
+        slapi_ch_free_string(&abs_configdir);
dc8c34
         return( NULL );
dc8c34
     }
dc8c34
     slapi_ch_free_string(&abs_configdir);
dc8c34
diff --git a/ldap/servers/slapd/tools/rsearch/sdattable.c b/ldap/servers/slapd/tools/rsearch/sdattable.c
dc8c34
index c0274d0..18417a1 100644
dc8c34
--- a/ldap/servers/slapd/tools/rsearch/sdattable.c
dc8c34
+++ b/ldap/servers/slapd/tools/rsearch/sdattable.c
dc8c34
@@ -141,27 +141,43 @@ int sdt_load(SDatTable *sdt, const char *filename)
dc8c34
     if (!fd) return 0;
dc8c34
 
dc8c34
     while (PR_Available(fd) > 0) {
dc8c34
-	int rval;
dc8c34
-	char temp[256];
dc8c34
-	char *dn = NULL;
dc8c34
-	char *uid = NULL;
dc8c34
-	while (!(rval = PR_GetLine(fd, temp, 256))) {
dc8c34
-	    char *p;
dc8c34
-	    if (!strncasecmp(temp, "dn:", 3)) {
dc8c34
-		for (p = temp + 4; *p == ' ' || *p == '\t'; p++) ;
dc8c34
-	        dn = strdup(p);
dc8c34
-	        if (!dn) break;
dc8c34
-	    } else if (!strncasecmp(temp, "uid:", 4)) {
dc8c34
-		for (p = temp + 5; *p == ' ' || *p == '\t'; p++) ;
dc8c34
-	        uid = strdup(p);
dc8c34
-	        if (!uid) break;
dc8c34
-	    }
dc8c34
-	    if (uid) {	/* dn should come earlier than uid */
dc8c34
-	        if (!sdt_push(sdt, dn, uid)) goto out;
dc8c34
-		break;
dc8c34
-	    }
dc8c34
-	}
dc8c34
-	if (rval) break;	/* PR_GetLine failed */
dc8c34
+		int rval;
dc8c34
+		int pushed = 0;
dc8c34
+		char temp[256];
dc8c34
+		char *dn = NULL;
dc8c34
+		char *uid = NULL;
dc8c34
+		while (!(rval = PR_GetLine(fd, temp, 256))) {
dc8c34
+			char *p;
dc8c34
+			if (!strncasecmp(temp, "dn:", 3)) {
dc8c34
+				for (p = temp + 4; *p == ' ' || *p == '\t'; p++) ;
dc8c34
+				dn = strdup(p);
dc8c34
+				if (!dn) break;
dc8c34
+			} else if (!strncasecmp(temp, "uid:", 4)) {
dc8c34
+				for (p = temp + 5; *p == ' ' || *p == '\t'; p++) ;
dc8c34
+				uid = strdup(p);
dc8c34
+				if (!uid) break;
dc8c34
+			}
dc8c34
+			if (uid) {
dc8c34
+				/* dn should come earlier than uid - so both dn and uid must be set. */
dc8c34
+				if (!sdt_push(sdt, dn, uid)){
dc8c34
+					/* failure, free the dn and uid */
dc8c34
+					free(dn);
dc8c34
+					free(uid);
dc8c34
+					goto out;
dc8c34
+				}
dc8c34
+				pushed = 1;
dc8c34
+				break;
dc8c34
+			}
dc8c34
+		}
dc8c34
+		if(!pushed){
dc8c34
+			/*
dc8c34
+			 * Entry might not have been a user entry with a uid,
dc8c34
+			 * so free the dn just in case.
dc8c34
+			 */
dc8c34
+			if(dn)
dc8c34
+				free(dn);
dc8c34
+		}
dc8c34
+		if (rval) break;	/* PR_GetLine failed */
dc8c34
     }
dc8c34
 out:
dc8c34
     PR_Close(fd);
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34