andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame 0227-Ticket-47820-1.2.11-branch-coverity-errors.patch

dc8c34
From 3db0b40f39d05e2aeacd1fe0dbd69b77608aa34c Mon Sep 17 00:00:00 2001
dc8c34
From: Noriko Hosoi <nhosoi@redhat.com>
dc8c34
Date: Thu, 19 Jun 2014 17:28:39 -0700
dc8c34
Subject: [PATCH 227/228] Ticket #47820 - 1.2.11 branch: coverity errors
dc8c34
MIME-Version: 1.0
dc8c34
Content-Type: text/plain; charset=UTF-8
dc8c34
Content-Transfer-Encoding: 8bit
dc8c34
dc8c34
Description:
dc8c34
* Deadcode
dc8c34
1. Defect type: UNUSED_VALUE
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1894:returned_pointer – Pointer "slapdFrontendConfig" returned by "getFrontendConfig()" is never used.
dc8c34
   Solution: removed the line 1894.
dc8c34
dc8c34
* Clang
dc8c34
1. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/valueset.c:1116:20:warning – Array access (via field 'va') results in a null pointer dereference
dc8c34
2. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/valueset.c:1090:26:warning – Array access (via field 'va') results in a null pointer dereference
dc8c34
   Solution: Added the code to check null dereference on vs->va on vs->va
dc8c34
dc8c34
3. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1896:6:warning – Value stored to 'maxthreads' during its initialization is never read
dc8c34
   Solution: removed the line 1896.
dc8c34
dc8c34
4. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1894:25:warning – Value stored to 'slapdFrontendConfig' during its initialization is never read
dc8c34
   Solution: Already addressed in Deadcode : 1. Defect type: UNUSED_VALUE
dc8c34
dc8c34
5. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1091:21:warning – Dereference of null pointer (loaded from variable 'nap')
dc8c34
   Solution: Added the code to check null dereference on nap and *nap.
dc8c34
dc8c34
6. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/back-ldbm/ldbm_search.c:455:25:warning – Value stored to 'virtual_list_view' is never read
dc8c34
   Solution: Porting bug (bz1109952; DS 47780).  Moved the line to the right position.
dc8c34
dc8c34
7. Defect type: CLANG_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/back-ldbm/ldbm_add.c:1110:2:warning – Value stored to 'noabort' is never read
dc8c34
   Solution: Removed unnecessary assignment.
dc8c34
dc8c34
Compiler Warnings
dc8c34
12. Defect type: COMPILER_WARNING
dc8c34
2. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1896:warning – unused variable 'maxthreads'
dc8c34
   Solution: already addressed 3. Defect type: CLANG_WARNING
dc8c34
dc8c34
13. Defect type: COMPILER_WARNING
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1895:warning – unused variable 'idletimeout'
dc8c34
   Solution: Removed the unused variable.
dc8c34
dc8c34
14. Defect type: COMPILER_WARNING ¶
dc8c34
1. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1894:warning – unused variable 'slapdFrontendConfig'
dc8c34
   Solution: already addressed 1. Defect type: UNUSED_VALUE
dc8c34
dc8c34
15. Defect type: COMPILER_WARNING
dc8c34
2. 389-ds-base-1.2.11.15/ldap/servers/slapd/daemon.c:1788:warning – 'compute_idletimeout' defined but not used
dc8c34
   Solution: removed the unused function.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47820
dc8c34
dc8c34
Reviewed by rmeggins@redhat.com (Thanks, Rich!!)
dc8c34
(cherry picked from commit ef7473dde11aa5c2b0041912b3f11099bb39ead8)
dc8c34
---
dc8c34
 ldap/servers/plugins/cos/cos_cache.c       | 13 +++++---
dc8c34
 ldap/servers/slapd/back-ldbm/ldbm_add.c    |  1 -
dc8c34
 ldap/servers/slapd/back-ldbm/ldbm_search.c | 50 ++++++++++++++----------------
dc8c34
 ldap/servers/slapd/daemon.c                |  8 ++---
dc8c34
 ldap/servers/slapd/valueset.c              |  7 ++++-
dc8c34
 5 files changed, 41 insertions(+), 38 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/cos/cos_cache.c b/ldap/servers/plugins/cos/cos_cache.c
dc8c34
index 1ff02f9..a89f5c5 100644
dc8c34
--- a/ldap/servers/plugins/cos/cos_cache.c
dc8c34
+++ b/ldap/servers/plugins/cos/cos_cache.c
dc8c34
@@ -942,7 +942,7 @@ cos_dn_defs_cb (Slapi_Entry* e, void *callback_data)
dc8c34
 			parent = slapi_create_dn_string("%s", orig);
dc8c34
 			if (!parent) {
dc8c34
 				parent = orig;
dc8c34
-				LDAPDebug1Arg(LDAP_DEBUG_ANY, 
dc8c34
+				slapi_log_error(SLAPI_LOG_FATAL, COS_PLUGIN_SUBSYSTEM,
dc8c34
 				              "cos_dn_defs_cb: "
dc8c34
 				              "failed to normalize parent dn %s. "
dc8c34
 				              "Adding the pre normalized dn.\n", 
dc8c34
@@ -959,18 +959,21 @@ cos_dn_defs_cb (Slapi_Entry* e, void *callback_data)
dc8c34
 			}
dc8c34
 			slapi_ch_free_string(&orig);
dc8c34
 		} else {
dc8c34
-			LDAPDebug1Arg(LDAP_DEBUG_ANY, 
dc8c34
+			slapi_log_error(SLAPI_LOG_FATAL, COS_PLUGIN_SUBSYSTEM,
dc8c34
 			              "cos_dn_defs_cb: "
dc8c34
 			              "failed to get parent dn of cos definition %s.\n",
dc8c34
 			              pDn->val);
dc8c34
 			if (!pCosTemplateDn) {
dc8c34
 				if (!pCosTargetTree) {
dc8c34
-					LDAPDebug0Args(LDAP_DEBUG_ANY, "cosTargetTree and cosTemplateDn are not set.\n");
dc8c34
+					slapi_log_error(SLAPI_LOG_FATAL, COS_PLUGIN_SUBSYSTEM,
dc8c34
+					                "cosTargetTree and cosTemplateDn are not set.\n");
dc8c34
 				} else {
dc8c34
-					LDAPDebug0Args(LDAP_DEBUG_ANY, "cosTemplateDn is not set.\n");
dc8c34
+					slapi_log_error(SLAPI_LOG_FATAL, COS_PLUGIN_SUBSYSTEM,
dc8c34
+					                "cosTemplateDn is not set.\n");
dc8c34
 				}
dc8c34
 			} else if (!pCosTargetTree) {
dc8c34
-				LDAPDebug0Args(LDAP_DEBUG_ANY, "cosTargetTree is not set.\n");
dc8c34
+				slapi_log_error(SLAPI_LOG_FATAL, COS_PLUGIN_SUBSYSTEM,
dc8c34
+				                "cosTargetTree is not set.\n");
dc8c34
 			}
dc8c34
 		}
dc8c34
 	}
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
dc8c34
index b129307..6361bc7 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
dc8c34
@@ -1107,7 +1107,6 @@ ldbm_back_add( Slapi_PBlock *pb )
dc8c34
 		}
dc8c34
 		goto error_return; 
dc8c34
 	}
dc8c34
-	noabort = 1;
dc8c34
 
dc8c34
 	rc= 0;
dc8c34
 	goto common_return;
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
dc8c34
index 626ba2e..46f7413 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
dc8c34
@@ -462,34 +462,32 @@ ldbm_back_search( Slapi_PBlock *pb )
dc8c34
                     }
dc8c34
 
dc8c34
                 } else {
dc8c34
-                    {
dc8c34
-                        /* Access Control Check to see if the client is allowed to use the VLV Control. */
dc8c34
-                        Slapi_Entry *feature;
dc8c34
-                        int rc;
dc8c34
-                        char dn[128];
dc8c34
-                        char *dummyAttr = "dummy#attr";
dc8c34
-                        char *dummyAttrs[2] = {NULL, NULL};
dc8c34
-
dc8c34
-                        dummyAttrs[0] = dummyAttr;
dc8c34
-
dc8c34
-                        /* This dn is normalized. */
dc8c34
-                        PR_snprintf(dn, sizeof (dn), "dn: oid=%s,cn=features,cn=config", LDAP_CONTROL_VLVREQUEST);
dc8c34
-                        feature = slapi_str2entry(dn, 0);
dc8c34
-                        rc = plugin_call_acl_plugin(pb, feature, dummyAttrs, NULL, SLAPI_ACL_READ, ACLPLUGIN_ACCESS_DEFAULT, NULL);
dc8c34
-                        slapi_entry_free(feature);
dc8c34
-                        if (rc != LDAP_SUCCESS) {
dc8c34
-                            /* Client isn't allowed to do this. */
dc8c34
-                            return ldbm_back_search_cleanup(pb, li, sort_control,
dc8c34
+                    /* Access Control Check to see if the client is allowed to use the VLV Control. */
dc8c34
+                    Slapi_Entry *feature;
dc8c34
+                    int rc;
dc8c34
+                    char dn[128];
dc8c34
+                    char *dummyAttr = "dummy#attr";
dc8c34
+                    char *dummyAttrs[2] = {NULL, NULL};
dc8c34
+
dc8c34
+                    dummyAttrs[0] = dummyAttr;
dc8c34
+
dc8c34
+                    /* This dn is normalized. */
dc8c34
+                    PR_snprintf(dn, sizeof (dn), "dn: oid=%s,cn=features,cn=config", LDAP_CONTROL_VLVREQUEST);
dc8c34
+                    feature = slapi_str2entry(dn, 0);
dc8c34
+                    rc = plugin_call_acl_plugin(pb, feature, dummyAttrs, NULL, SLAPI_ACL_READ, ACLPLUGIN_ACCESS_DEFAULT, NULL);
dc8c34
+                    slapi_entry_free(feature);
dc8c34
+                    if (rc != LDAP_SUCCESS) {
dc8c34
+                        /* Client isn't allowed to do this. */
dc8c34
+                        return ldbm_back_search_cleanup(pb, li, sort_control,
dc8c34
                                     rc, "VLV Control", SLAPI_FAIL_GENERAL,
dc8c34
                                     &vlv_request_control, NULL, candidates);
dc8c34
-                        }
dc8c34
                     }
dc8c34
+                    /*
dc8c34
+                     * Sorting must always be critical for VLV; Force it be so.
dc8c34
+                     */
dc8c34
+                    is_sorting_critical= 1;
dc8c34
+                    virtual_list_view= 1;
dc8c34
                 }
dc8c34
-                /*
dc8c34
-                 * Sorting must always be critical for VLV; Force it be so.
dc8c34
-                 */
dc8c34
-                is_sorting_critical= 1;
dc8c34
-                virtual_list_view= 1;
dc8c34
             }
dc8c34
             else
dc8c34
             {
dc8c34
@@ -1407,7 +1405,7 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension )
dc8c34
     back_txn               txn = {NULL};
dc8c34
     int                    pr_idx = -1;
dc8c34
     Slapi_Connection       *conn;
dc8c34
-    Slapi_Operation        *op;
dc8c34
+    Slapi_Operation        *op = NULL;
dc8c34
     int                    reverse_list = 0;
dc8c34
 
dc8c34
     slapi_pblock_get( pb, SLAPI_SEARCH_TARGET_SDN, &basesdn );
dc8c34
@@ -1791,7 +1789,7 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension )
dc8c34
     }
dc8c34
 
dc8c34
 bail:
dc8c34
-    if(rc){
dc8c34
+    if(rc && op) {
dc8c34
         op->o_reverse_search_state = 0;
dc8c34
     }
dc8c34
 
dc8c34
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
dc8c34
index ebd3e0f..9a362c7 100644
dc8c34
--- a/ldap/servers/slapd/daemon.c
dc8c34
+++ b/ldap/servers/slapd/daemon.c
dc8c34
@@ -1081,7 +1081,7 @@ void slapd_daemon( daemon_ports_t *ports )
dc8c34
 	if ( n_tcps != NULL ) {
dc8c34
 		PRFileDesc **fdesp;
dc8c34
 		PRNetAddr  **nap = ports->n_listenaddr;
dc8c34
-		for (fdesp = n_tcps; fdesp && *fdesp; fdesp++, nap++) {
dc8c34
+		for (fdesp = n_tcps; fdesp && *fdesp && nap && *nap; fdesp++, nap++) {
dc8c34
 			if ( PR_Listen( *fdesp, config_get_listen_backlog_size() ) == PR_FAILURE ) {
dc8c34
 				PRErrorCode prerr = PR_GetError();
dc8c34
 				char		addrbuf[ 256 ];
dc8c34
@@ -1779,6 +1779,7 @@ daemon_register_reslimits( void )
dc8c34
 			&idletimeout_reslimit_handle ));
dc8c34
 }
dc8c34
 
dc8c34
+#if 0 /* NOT USED */
dc8c34
 /*
dc8c34
  * Compute the idle timeout for the connection.
dc8c34
  *
dc8c34
@@ -1826,7 +1827,7 @@ compute_idletimeout( slapdFrontendConfig_t *fecfg, Connection *conn )
dc8c34
 
dc8c34
 	return( idletimeout );
dc8c34
 }
dc8c34
-
dc8c34
+#endif
dc8c34
 
dc8c34
 #ifdef _WIN32
dc8c34
 static void
dc8c34
@@ -1891,9 +1892,6 @@ handle_pr_read_ready(Connection_Table *ct, PRIntn num_poll)
dc8c34
 {
dc8c34
 	Connection *c;
dc8c34
 	time_t curtime = current_time();
dc8c34
-	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
-	int idletimeout;
dc8c34
-	int maxthreads = config_get_maxthreadsperconn();
dc8c34
 #if defined( XP_WIN32 )
dc8c34
 	int i;
dc8c34
 #endif
dc8c34
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
dc8c34
index 960ad79..5c1ae36 100644
dc8c34
--- a/ldap/servers/slapd/valueset.c
dc8c34
+++ b/ldap/servers/slapd/valueset.c
dc8c34
@@ -1038,7 +1038,7 @@ slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs,
dc8c34
 	int passin = flags & SLAPI_VALUE_FLAG_PASSIN;
dc8c34
 	int dupcheck = flags & SLAPI_VALUE_FLAG_DUPCHECK;
dc8c34
 
dc8c34
-	if (naddvals == 0) 
dc8c34
+	if (naddvals <= 0) 
dc8c34
 		return (rc);
dc8c34
 	
dc8c34
 	need = vs->num + naddvals + 1;
dc8c34
@@ -1072,6 +1072,11 @@ slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs,
dc8c34
 		}
dc8c34
 		vs->max= allocate;
dc8c34
 	}
dc8c34
+	if (NULL == vs->va) {
dc8c34
+		LDAPDebug1Arg(LDAP_DEBUG_ANY, "slapi_valueset_add_attr_valuearray_ext: "
dc8c34
+		              "%s: valuearray is NULL\n", a->a_type);
dc8c34
+		return LDAP_OPERATIONS_ERROR;
dc8c34
+	}
dc8c34
 
dc8c34
 	if ( (vs->num + naddvals > VALUESET_ARRAY_SORT_THRESHOLD || dupcheck ) && 
dc8c34
 		!vs->sorted ) {
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34