andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
74ca47
From 97f09918ef370c3be5aa64dcfeb3bb21e762f90d Mon Sep 17 00:00:00 2001
74ca47
From: Mark Reynolds <mreynolds@redhat.com>
74ca47
Date: Tue, 14 Mar 2017 20:23:07 -0400
74ca47
Subject: [PATCH 4/5] Issue 49169 - Fix covscan errors
74ca47
74ca47
src/libsds/bpt/map.c  - resource leak
74ca47
ldap/servers/slapd/vattr.c - resource leak
74ca47
ldap/servers/slapd/task.c:  resource leaks
74ca47
ldap/servers/slapd/str2filter.c - resource leak
74ca47
ldap/servers/slapd/pw.c - resource leak
74ca47
ldap/servers/slapd/back-ldbm/import-threads.c - resource leak
74ca47
ldap/servers/plugins/uiduniq/uid.c:536 - resource leak
74ca47
ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c:164 - resource leak
74ca47
ldap/servers/plugins/linkedattrs/linked_attrs.c:1672 - resource leak
74ca47
ldap/servers/plugins/addn/addn.c:419
74ca47
ldap/servers/slapd/ssl.c - dead code
74ca47
ldap/servers/slapd/index_subsystem.c - null dereference
74ca47
74ca47
https://pagure.io/389-ds-base/issue/49169
74ca47
74ca47
Reviewed by: nkinder & wibrown(Thanks!!)
74ca47
74ca47
(cherry picked from commit c75126be1edece121826e336141f9b0b9c0bddfd)
74ca47
---
74ca47
 ldap/servers/plugins/addn/addn.c                |  4 +++-
74ca47
 ldap/servers/plugins/linkedattrs/linked_attrs.c |  2 ++
74ca47
 ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c    |  1 +
74ca47
 ldap/servers/plugins/uiduniq/uid.c              |  6 +++++-
74ca47
 ldap/servers/slapd/back-ldbm/import-threads.c   |  1 +
74ca47
 ldap/servers/slapd/index_subsystem.c            | 27 +++++++++++++------------
74ca47
 ldap/servers/slapd/pw.c                         |  1 +
74ca47
 ldap/servers/slapd/pw_verify.c                  |  1 -
74ca47
 ldap/servers/slapd/ssl.c                        |  8 +++-----
74ca47
 ldap/servers/slapd/str2filter.c                 |  1 +
74ca47
 ldap/servers/slapd/task.c                       |  3 +--
74ca47
 ldap/servers/slapd/vattr.c                      |  6 +++---
74ca47
 src/libsds/sds/bpt/map.c                        |  1 +
74ca47
 13 files changed, 36 insertions(+), 26 deletions(-)
74ca47
74ca47
diff --git a/ldap/servers/plugins/addn/addn.c b/ldap/servers/plugins/addn/addn.c
74ca47
index 3abc112..6ba7833 100644
74ca47
--- a/ldap/servers/plugins/addn/addn.c
74ca47
+++ b/ldap/servers/plugins/addn/addn.c
74ca47
@@ -415,7 +415,9 @@ addn_start(Slapi_PBlock *pb)
74ca47
     domain = slapi_entry_attr_get_charptr(plugin_entry, "addn_default_domain");
74ca47
 
74ca47
     if (domain == NULL) {
74ca47
-        slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_start: CRITICAL: No default domain in configuration, you must set addn_default_domain!\n");
74ca47
+        slapi_log_err(SLAPI_LOG_ERR, plugin_name,
74ca47
+                "addn_start: CRITICAL: No default domain in configuration, you must set addn_default_domain!\n");
74ca47
+        slapi_ch_free((void**)&config);
74ca47
         return SLAPI_PLUGIN_FAILURE;
74ca47
     }
74ca47
 
74ca47
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
74ca47
index b5adb21..d046542 100644
74ca47
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
74ca47
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
74ca47
@@ -1669,6 +1669,8 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
74ca47
             /* Bail out if the plug-in close function was just called. */
74ca47
             if (!slapi_plugin_running(pb)) {
74ca47
                 linked_attrs_unlock();
74ca47
+                slapi_mod_free(&next_mod);
74ca47
+                slapi_mods_free(&smods);
74ca47
                 return SLAPI_PLUGIN_SUCCESS;
74ca47
             }
74ca47
 
74ca47
diff --git a/ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c b/ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c
74ca47
index 1b3e555..b228700 100644
74ca47
--- a/ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c
74ca47
+++ b/ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c
74ca47
@@ -161,6 +161,7 @@ pbkdf2_sha256_pw_enc(const char *pwd)
74ca47
      */
74ca47
     if ( pbkdf2_sha256_hash(hash + PBKDF2_ITERATIONS_LENGTH + PBKDF2_SALT_LENGTH, PBKDF2_HASH_LENGTH, &passItem, &saltItem, PBKDF2_ITERATIONS) != SECSuccess ) {
74ca47
         slapi_log_err(SLAPI_LOG_ERR, (char *)schemeName, "Could not generate pbkdf2_sha256_hash!\n");
74ca47
+        slapi_ch_free_string(&enc;;
74ca47
         return NULL;
74ca47
     }
74ca47
 
74ca47
diff --git a/ldap/servers/plugins/uiduniq/uid.c b/ldap/servers/plugins/uiduniq/uid.c
74ca47
index ae9320e..46554b2 100644
74ca47
--- a/ldap/servers/plugins/uiduniq/uid.c
74ca47
+++ b/ldap/servers/plugins/uiduniq/uid.c
74ca47
@@ -533,7 +533,11 @@ create_filter(const char **attributes, const struct berval *value, const char *r
74ca47
 
74ca47
           /* Place value in filter */
74ca47
           if (ldap_quote_filter_value(value->bv_val, value->bv_len,
74ca47
-            fp, max-fp, &valueLen)) { slapi_ch_free((void**)&filter); return 0; }
74ca47
+                                      fp, max-fp, &valueLen)) {
74ca47
+              slapi_ch_free((void**)&filter);
74ca47
+              slapi_ch_free((void**)&attrLen);
74ca47
+              return 0;
74ca47
+          }
74ca47
           fp += valueLen;
74ca47
 
74ca47
           strcpy(fp, ")");
74ca47
diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c
74ca47
index 5b81427..087103b 100644
74ca47
--- a/ldap/servers/slapd/back-ldbm/import-threads.c
74ca47
+++ b/ldap/servers/slapd/back-ldbm/import-threads.c
74ca47
@@ -1647,6 +1647,7 @@ upgradedn_producer(void *param)
74ca47
                 }
74ca47
                 e = slapi_str2entry_ext(normdn, NULL, data.dptr, 
74ca47
                                         SLAPI_STR2ENTRY_USE_OBSOLETE_DNFORMAT);
74ca47
+                slapi_ch_free_string(&rdn;;
74ca47
             }
74ca47
         } else {
74ca47
             e = 
74ca47
diff --git a/ldap/servers/slapd/index_subsystem.c b/ldap/servers/slapd/index_subsystem.c
74ca47
index 57d4f58..8f9fe6d 100644
74ca47
--- a/ldap/servers/slapd/index_subsystem.c
74ca47
+++ b/ldap/servers/slapd/index_subsystem.c
74ca47
@@ -185,27 +185,28 @@ static int index_subsys_index_matches_filter(indexEntry *index, Slapi_Filter *f)
74ca47
  */
74ca47
 int index_subsys_assign_filter_decoders(Slapi_PBlock *pb)
74ca47
 {
74ca47
-	int				rc;
74ca47
+	int				rc = 0;
74ca47
 	Slapi_Filter	*f;
74ca47
 	char			*subsystem = "index_subsys_assign_filter_decoders";
74ca47
 	char			logbuf[ 1024 ];
74ca47
 
74ca47
 	/* extract the filter */
74ca47
 	slapi_pblock_get(pb, SLAPI_SEARCH_FILTER, &f);   
74ca47
+	if (f) {
74ca47
+		if ( loglevel_is_set( LDAP_DEBUG_FILTER )) {
74ca47
+			logbuf[0] = '\0';
74ca47
+			slapi_log_err(SLAPI_LOG_DEBUG, subsystem, "before: %s\n",
74ca47
+					slapi_filter_to_string(f, logbuf, sizeof(logbuf)));
74ca47
+		}
74ca47
 
74ca47
-	if ( loglevel_is_set( LDAP_DEBUG_FILTER ) && NULL != f ) {
74ca47
-		logbuf[0] = '\0';
74ca47
-		slapi_log_err(SLAPI_LOG_DEBUG, subsystem, "before: %s\n",
74ca47
-				slapi_filter_to_string(f, logbuf, sizeof(logbuf)));
74ca47
-	}
74ca47
-
74ca47
-	/* find decoders */
74ca47
-	rc = index_subsys_assign_decoders(f);
74ca47
+		/* find decoders */
74ca47
+		rc = index_subsys_assign_decoders(f);
74ca47
 
74ca47
-	if ( loglevel_is_set( LDAP_DEBUG_FILTER ) && NULL != f ) {
74ca47
-		logbuf[0] = '\0';
74ca47
-		slapi_log_err(SLAPI_LOG_DEBUG, subsystem, " after: %s\n",
74ca47
-				slapi_filter_to_string(f, logbuf, sizeof(logbuf)));
74ca47
+		if ( loglevel_is_set( LDAP_DEBUG_FILTER )) {
74ca47
+			logbuf[0] = '\0';
74ca47
+			slapi_log_err(SLAPI_LOG_DEBUG, subsystem, " after: %s\n",
74ca47
+					slapi_filter_to_string(f, logbuf, sizeof(logbuf)));
74ca47
+		}
74ca47
 	}
74ca47
 
74ca47
 	return rc;
74ca47
diff --git a/ldap/servers/slapd/pw.c b/ldap/servers/slapd/pw.c
74ca47
index 215c9eb..378d148 100644
74ca47
--- a/ldap/servers/slapd/pw.c
74ca47
+++ b/ldap/servers/slapd/pw.c
74ca47
@@ -1512,6 +1512,7 @@ check_trivial_words (Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Value **vals, char
74ca47
 			ep = sp + strlen(sp);
74ca47
 			ep = ldap_utf8prevn(sp, ep, toklen);
74ca47
 			if (!ep || (sp >= ep)) {
74ca47
+				slapi_ch_free_string(&sp);
74ca47
 				continue;
74ca47
 			}
74ca47
 			/* See if the password contains the value */
74ca47
diff --git a/ldap/servers/slapd/pw_verify.c b/ldap/servers/slapd/pw_verify.c
74ca47
index 529bb83..a9fd9ec 100644
74ca47
--- a/ldap/servers/slapd/pw_verify.c
74ca47
+++ b/ldap/servers/slapd/pw_verify.c
74ca47
@@ -103,7 +103,6 @@ pw_verify_be_dn(Slapi_PBlock *pb, Slapi_Entry **referral)
74ca47
 int
74ca47
 pw_validate_be_dn(Slapi_PBlock *pb, Slapi_Entry **referral)
74ca47
 {
74ca47
-    int rc = 0;
74ca47
     Slapi_Backend *be = NULL;
74ca47
     Slapi_DN *pb_sdn;
74ca47
     struct berval *cred;
74ca47
diff --git a/ldap/servers/slapd/ssl.c b/ldap/servers/slapd/ssl.c
74ca47
index f35b3f1..050e7b5 100644
74ca47
--- a/ldap/servers/slapd/ssl.c
74ca47
+++ b/ldap/servers/slapd/ssl.c
74ca47
@@ -1418,12 +1418,10 @@ slapd_ssl_init()
74ca47
       errorCode = PR_GetError();
74ca47
       slapd_SSL_error("Failed to retrieve SSL "
74ca47
                      "configuration information ("
74ca47
-                     SLAPI_COMPONENT_NAME_NSPR " error %d - %s): "
74ca47
+                     SLAPI_COMPONENT_NAME_NSPR " error %d - not found): "
74ca47
                      "nssslSessionTimeout: %s ",
74ca47
-                     errorCode, slapd_pr_strerror(errorCode),
74ca47
-             (val ? "found" : "not found"));
74ca47
-      slapi_ch_free((void **) &val;;
74ca47
-      slapi_ch_free((void **) &ciphers);
74ca47
+                     errorCode, slapd_pr_strerror(errorCode));
74ca47
+      slapi_ch_free((void **)&ciphers);
74ca47
       freeConfigEntry( &entry );
74ca47
       return -1;
74ca47
     }
74ca47
diff --git a/ldap/servers/slapd/str2filter.c b/ldap/servers/slapd/str2filter.c
74ca47
index ebd5c5d..744c93f 100644
74ca47
--- a/ldap/servers/slapd/str2filter.c
74ca47
+++ b/ldap/servers/slapd/str2filter.c
74ca47
@@ -344,6 +344,7 @@ str2simple( char *str , int unescape_filter)
74ca47
 			*endp = '\0';
74ca47
 			rc = _parse_ext_filter(str, extp, &f->f_mr_type, &f->f_mr_oid, &f->f_mr_dnAttrs);
74ca47
 			if (rc) {
74ca47
+				slapi_filter_free(f, 1);
74ca47
 				return NULL; /* error */
74ca47
 			} else {
74ca47
 				f->f_choice = LDAP_FILTER_EXTENDED;
74ca47
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
74ca47
index ad52e9d..eabd517 100644
74ca47
--- a/ldap/servers/slapd/task.c
74ca47
+++ b/ldap/servers/slapd/task.c
74ca47
@@ -2389,7 +2389,6 @@ task_fixup_tombstones_add(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *eAfter,
74ca47
         slapi_task_finish(task, *returncode);
74ca47
         slapi_ch_array_free(base);
74ca47
         slapi_ch_free((void **)&task_data);
74ca47
-        return SLAPI_DSE_CALLBACK_ERROR;
74ca47
     }
74ca47
 
74ca47
 done:
74ca47
@@ -2507,9 +2506,9 @@ task_des2aes(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *eAfter,
74ca47
 error:
74ca47
     if (rc == SLAPI_DSE_CALLBACK_ERROR){
74ca47
         slapi_ch_array_free(bases);
74ca47
-        slapi_ch_array_free(suffix);
74ca47
         slapi_ch_free((void **)&task_data);
74ca47
     }
74ca47
+    slapi_ch_array_free(suffix);
74ca47
     return rc;
74ca47
 }
74ca47
 
74ca47
diff --git a/ldap/servers/slapd/vattr.c b/ldap/servers/slapd/vattr.c
74ca47
index 34665de..599b54e 100644
74ca47
--- a/ldap/servers/slapd/vattr.c
74ca47
+++ b/ldap/servers/slapd/vattr.c
74ca47
@@ -753,10 +753,10 @@ slapi_vattr_values_get_sp(vattr_context *c,
74ca47
   }
74ca47
   if (use_local_ctx) {
74ca47
     /* slapi_pblock_destroy cleans up pb_vattr_context, as well */
74ca47
-    slapi_pblock_destroy(local_pb);
74ca47
-  } else {
74ca47
-    vattr_context_ungrok(&c);
74ca47
+	slapi_pblock_destroy(local_pb);
74ca47
+	ctx->pb = NULL;
74ca47
   }
74ca47
+  vattr_context_ungrok(&ctx;;
74ca47
   return rc;
74ca47
 }
74ca47
 
74ca47
diff --git a/src/libsds/sds/bpt/map.c b/src/libsds/sds/bpt/map.c
74ca47
index 4205aa5..2c3468b 100644
74ca47
--- a/src/libsds/sds/bpt/map.c
74ca47
+++ b/src/libsds/sds/bpt/map.c
74ca47
@@ -18,6 +18,7 @@ sds_bptree_map_nodes(sds_bptree_instance *binst, sds_bptree_node *root, sds_resu
74ca47
     sds_bptree_node_list *tail = cur;
74ca47
 
74ca47
     if (binst == NULL) {
74ca47
+        sds_free(cur);
74ca47
         return SDS_NULL_POINTER;
74ca47
     }
74ca47
 
74ca47
-- 
74ca47
2.9.3
74ca47