andykimpe / rpms / 389-ds-base

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