andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From e767924756756993ea08c1636ee6d1af3e2775b0 Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Tue, 4 Jun 2013 13:25:22 -0400
dc8c34
Subject: [PATCH 90/99] Coverity Fixes (Part 2)
dc8c34
dc8c34
11674 - logically dead code (collate.c)
dc8c34
11675 - logically dead code (windows_protocol_util.c)
dc8c34
11676 - logically dead code (index.c)
dc8c34
11677 - logically dead code (ldbm_entryrdn.c)
dc8c34
11678 - logically dead code (ldbm_entryrdn.c)
dc8c34
11680 - logically dead code (ldbm_search.c)
dc8c34
11681 - Dead default in switch (seq.c)
dc8c34
11683 - logically dead code (bind.c)
dc8c34
11684 - logically dead code (connection.c)
dc8c34
11686 - Dead default in switch (log.c)
dc8c34
11687 - Dead default in switch (log.c)
dc8c34
11688 - Dead default in switch (log.c)
dc8c34
11689 - Dead default in switch (log.c)
dc8c34
11690 - Dead default in switch (log.c)
dc8c34
11691 - Dead default in switch (log.c)
dc8c34
dc8c34
https://bugzilla.redhat.com/show_bug.cgi?id=970221
dc8c34
dc8c34
Reviewed by: nhosoi(Thanks!)
dc8c34
(cherry picked from commit db673270e9a01e48adb22d94e676f25a223f407b)
dc8c34
(cherry picked from commit 41a882743c7c21575ed5365fe0484bc8d96edc6f)
dc8c34
---
dc8c34
 ldap/servers/plugins/collation/collate.c           | 24 +++++------
dc8c34
 .../plugins/replication/windows_protocol_util.c    |  9 ++---
dc8c34
 ldap/servers/slapd/back-ldbm/index.c               | 17 ++++----
dc8c34
 ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c       | 24 +++--------
dc8c34
 ldap/servers/slapd/back-ldbm/ldbm_search.c         |  2 +-
dc8c34
 ldap/servers/slapd/back-ldbm/seq.c                 |  2 -
dc8c34
 ldap/servers/slapd/bind.c                          |  2 +-
dc8c34
 ldap/servers/slapd/log.c                           | 46 +++++-----------------
dc8c34
 8 files changed, 40 insertions(+), 86 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/collation/collate.c b/ldap/servers/plugins/collation/collate.c
dc8c34
index 240da70..2a73ee1 100644
dc8c34
--- a/ldap/servers/plugins/collation/collate.c
dc8c34
+++ b/ldap/servers/plugins/collation/collate.c
dc8c34
@@ -437,11 +437,7 @@ collation_indexer_create (const char* oid)
dc8c34
 					 profile->variant  == NULL);
dc8c34
 	    UErrorCode err = U_ZERO_ERROR;
dc8c34
 	    if ( ! is_default) {
dc8c34
-		if (locale) {
dc8c34
-		    PR_smprintf_free(locale);
dc8c34
-		    locale = NULL;
dc8c34
-		}
dc8c34
-		err = s_newNamedLocaleFromComponents(&locale,
dc8c34
+			err = s_newNamedLocaleFromComponents(&locale,
dc8c34
 						     profile->language,
dc8c34
 						     profile->country,
dc8c34
 						     profile->variant);
dc8c34
@@ -460,27 +456,27 @@ collation_indexer_create (const char* oid)
dc8c34
 		    ucol_setAttribute (coll, UCOL_STRENGTH, profile->strength, &err;;
dc8c34
 		    if (err != U_ZERO_ERROR && err != U_USING_FALLBACK_WARNING
dc8c34
 			&& (err != U_USING_DEFAULT_WARNING || !is_default)) {
dc8c34
-			LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
dc8c34
+		    	LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
dc8c34
 				   "set the collator strength for oid %s to %d: err %d\n",
dc8c34
 				   oid, profile->strength, err);
dc8c34
 		    }
dc8c34
 		    ucol_setAttribute (coll, UCOL_DECOMPOSITION_MODE, profile->decomposition, &err;;
dc8c34
 		    if (err != U_ZERO_ERROR && err != U_USING_FALLBACK_WARNING
dc8c34
 			&& (err != U_USING_DEFAULT_WARNING || !is_default)) {
dc8c34
-			LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
dc8c34
+		    	LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
dc8c34
 				   "set the collator decomposition mode for oid %s to %d: err %d\n",
dc8c34
 				   oid, profile->decomposition, err);
dc8c34
 		    }
dc8c34
 		    etc->collator = coll;
dc8c34
 		    for (id = collation_id; *id; ++id) {
dc8c34
-			if ((*id)->profile == profile) {
dc8c34
-			    break; /* found the 'official' id */
dc8c34
-			}
dc8c34
+		    	if ((*id)->profile == profile) {
dc8c34
+		    		break; /* found the 'official' id */
dc8c34
+		    	}
dc8c34
 		    }
dc8c34
-                    if (!*id) {
dc8c34
-			LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: id not found\n", 0, 0, 0);
dc8c34
-                        goto error;
dc8c34
-                    }
dc8c34
+            if (!*id) {
dc8c34
+                LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: id not found\n", 0, 0, 0);
dc8c34
+                goto error;
dc8c34
+            }
dc8c34
 
dc8c34
 		    ix->ix_etc = etc;
dc8c34
 		    ix->ix_oid = (*id)->oid;
dc8c34
diff --git a/ldap/servers/plugins/replication/windows_protocol_util.c b/ldap/servers/plugins/replication/windows_protocol_util.c
dc8c34
index 1bafa9a..0b3c575 100644
dc8c34
--- a/ldap/servers/plugins/replication/windows_protocol_util.c
dc8c34
+++ b/ldap/servers/plugins/replication/windows_protocol_util.c
dc8c34
@@ -4190,7 +4190,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
dc8c34
 		windows_is_remote_entry_user_or_group(remote_entry,&is_user,&is_group);
dc8c34
 	}
dc8c34
 
dc8c34
-        for (rc = slapi_entry_first_attr(remote_entry, &attr); rc == 0;
dc8c34
+    for (rc = slapi_entry_first_attr(remote_entry, &attr); rc == 0;
dc8c34
              rc = slapi_entry_next_attr(remote_entry, attr, &attr)) 
dc8c34
 	{
dc8c34
 		int is_present_local = 0;
dc8c34
@@ -4201,7 +4201,6 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
dc8c34
 		int is_guid = 0;
dc8c34
 		int mapdn = 0;
dc8c34
 
dc8c34
-
dc8c34
 		slapi_attr_get_type( attr, &type );
dc8c34
 		slapi_attr_get_valueset(attr,&vs);
dc8c34
 
dc8c34
@@ -4360,7 +4359,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
dc8c34
 											"windows_generate_update_mods: no restricted local values found for "
dc8c34
 											"local attribute %s in local entry %s for remote attribute "
dc8c34
 											"%s in remote entry %s\n",
dc8c34
-											local_type ? local_type : "NULL",
dc8c34
+											local_type,
dc8c34
 											slapi_entry_get_dn(local_entry),
dc8c34
 											type ? type : "NULL",
dc8c34
 											slapi_entry_get_dn(remote_entry));
dc8c34
@@ -4372,7 +4371,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
dc8c34
 										"windows_generate_update_mods: no local values found for "
dc8c34
 										"local attribute %s in local entry %s for remote attribute "
dc8c34
 										"%s in remote entry %s\n",
dc8c34
-										local_type ? local_type : "NULL",
dc8c34
+										local_type,
dc8c34
 										slapi_entry_get_dn(local_entry),
dc8c34
 										type ? type : "NULL",
dc8c34
 										slapi_entry_get_dn(remote_entry));
dc8c34
@@ -4384,7 +4383,7 @@ windows_generate_update_mods(Private_Repl_Protocol *prp,Slapi_Entry *remote_entr
dc8c34
 									"windows_generate_update_mods: could not map the values in "
dc8c34
 									"local attribute %s in local entry %s for remote attribute "
dc8c34
 									"%s in remote entry %s\n",
dc8c34
-									local_type ? local_type : "NULL",
dc8c34
+									local_type,
dc8c34
 									slapi_entry_get_dn(local_entry),
dc8c34
 									type ? type : "NULL",
dc8c34
 									slapi_entry_get_dn(remote_entry));
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
dc8c34
index 62a58a7..7769791 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/index.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/index.c
dc8c34
@@ -649,18 +649,17 @@ index_add_mods(
dc8c34
                             mods[i]->mod_op |= LDAP_MOD_IGNORE;
dc8c34
                         }
dc8c34
                     }
dc8c34
-                    if (mods_valueArray) {
dc8c34
-                        rc = index_addordel_values_sv( be,
dc8c34
-                                                   mods[i]->mod_type, 
dc8c34
-                                                   mods_valueArray, NULL,
dc8c34
-                                                   id, BE_INDEX_ADD, txn );
dc8c34
-                        if (rc) {
dc8c34
-                            ldbm_nasty(errmsg, 1042, rc);
dc8c34
-                            goto error;
dc8c34
-                        }
dc8c34
+                    if(mods_valueArray[0]){
dc8c34
+                        rc = index_addordel_values_sv( be, mods[i]->mod_type,
dc8c34
+                                                       mods_valueArray, NULL,
dc8c34
+                                                       id, BE_INDEX_ADD, txn );
dc8c34
                     } else {
dc8c34
                         rc = 0;
dc8c34
                     }
dc8c34
+                    if (rc) {
dc8c34
+                        ldbm_nasty(errmsg, 1042, rc);
dc8c34
+                        goto error;
dc8c34
+                    }
dc8c34
                 }
dc8c34
             }
dc8c34
             break;
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
dc8c34
index 4329b16..156461b 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
dc8c34
@@ -809,14 +809,8 @@ entryrdn_rename_subtree(backend *be,
dc8c34
                 renamedata.data = (void *)oldsupelem;
dc8c34
             }
dc8c34
         } else {
dc8c34
-            if (mynewsupsdn) {
dc8c34
-                renamedata.ulen = renamedata.size = newsupelemlen;
dc8c34
-                renamedata.data = (void *)newsupelem;
dc8c34
-            } else {
dc8c34
-                /* never comes here */
dc8c34
-                rc = -1;
dc8c34
-                goto bail;
dc8c34
-            }
dc8c34
+            renamedata.ulen = renamedata.size = newsupelemlen;
dc8c34
+            renamedata.data = (void *)newsupelem;
dc8c34
         }
dc8c34
         rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_PARENT, db_txn);
dc8c34
         if (rc) {
dc8c34
@@ -901,16 +895,10 @@ entryrdn_rename_subtree(backend *be,
dc8c34
                 renamedata.data = (void *)targetelem;
dc8c34
             }
dc8c34
         } else {
dc8c34
-            if (mynewsrdn) {
dc8c34
-                memset(&renamedata, 0, sizeof(renamedata));
dc8c34
-                renamedata.ulen = renamedata.size = newelemlen;
dc8c34
-                renamedata.data = (void *)newelem;
dc8c34
-                renamedata.flags = DB_DBT_USERMEM;
dc8c34
-            } else {
dc8c34
-                /* never comes here */
dc8c34
-                rc = -1;
dc8c34
-                goto bail;
dc8c34
-            }
dc8c34
+            memset(&renamedata, 0, sizeof(renamedata));
dc8c34
+            renamedata.ulen = renamedata.size = newelemlen;
dc8c34
+            renamedata.data = (void *)newelem;
dc8c34
+            renamedata.flags = DB_DBT_USERMEM;
dc8c34
         }
dc8c34
         rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_CHILD, db_txn);
dc8c34
         if (rc) {
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
dc8c34
index 670f627..e68b897 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
dc8c34
@@ -573,7 +573,7 @@ ldbm_back_search( Slapi_PBlock *pb )
dc8c34
             /* This candidate list is for vlv, no need for sort only. */
dc8c34
             switch (vlv_search_build_candidate_list(pb, basesdn, &vlv_rc,
dc8c34
                                                     sort_control,
dc8c34
-                                                    (vlv ? &vlv_request_control : NULL),
dc8c34
+                                                    &vlv_request_control,
dc8c34
                                                     &candidates, &vlv_response_control)) {
dc8c34
             case VLV_ACCESS_DENIED:
dc8c34
                 return ldbm_back_search_cleanup(pb, li, sort_control,
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/seq.c b/ldap/servers/slapd/back-ldbm/seq.c
dc8c34
index 1435ba2..ab473bd 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/seq.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/seq.c
dc8c34
@@ -221,8 +221,6 @@ ldbm_back_seq( Slapi_PBlock *pb )
dc8c34
 				}
dc8c34
 			}
dc8c34
 			break;
dc8c34
-		default:
dc8c34
-			PR_ASSERT(0);
dc8c34
 		}
dc8c34
 
dc8c34
 		dbc->c_close(dbc);
dc8c34
diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c
dc8c34
index e92add5..ec874cc 100644
dc8c34
--- a/ldap/servers/slapd/bind.c
dc8c34
+++ b/ldap/servers/slapd/bind.c
dc8c34
@@ -178,7 +178,7 @@ do_bind( Slapi_PBlock *pb )
dc8c34
         /* check that the dn is formatted correctly */
dc8c34
         rc = slapi_dn_syntax_check(pb, rawdn, 1);
dc8c34
         if (rc) { /* syntax check failed */
dc8c34
-            op_shared_log_error_access(pb, "BIND", rawdn?rawdn:"",
dc8c34
+            op_shared_log_error_access(pb, "BIND", rawdn,
dc8c34
                                        "strict: invalid bind dn");
dc8c34
             send_ldap_result(pb, LDAP_INVALID_DN_SYNTAX, 
dc8c34
                              NULL, "invalid bind dn", 0, NULL);
dc8c34
diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
dc8c34
index 9b3f640..72a918b 100644
dc8c34
--- a/ldap/servers/slapd/log.c
dc8c34
+++ b/ldap/servers/slapd/log.c
dc8c34
@@ -1011,8 +1011,6 @@ log_set_rotationsynchour(const char *attrname, char *rhour_str, int logtype, cha
dc8c34
 			fe_cfg->auditlog_rotationsynchour = rhour;
dc8c34
 			LOG_AUDIT_UNLOCK_WRITE();
dc8c34
 			break;
dc8c34
-		default:
dc8c34
-			rv = 1;
dc8c34
 	}
dc8c34
 
dc8c34
 	return rv;
dc8c34
@@ -1065,8 +1063,6 @@ log_set_rotationsyncmin(const char *attrname, char *rmin_str, int logtype, char
dc8c34
 		loginfo.log_audit_rotationsyncclock = log_get_rotationsyncclock( loginfo.log_audit_rotationsynchour, rmin );
dc8c34
 		LOG_AUDIT_UNLOCK_WRITE();
dc8c34
 		break;
dc8c34
-	   default:
dc8c34
-		rv = 1;
dc8c34
 	}
dc8c34
 
dc8c34
 	return rv;
dc8c34
@@ -1122,8 +1118,6 @@ log_set_rotationtime(const char *attrname, char *rtime_str, int logtype, char *r
dc8c34
 		loginfo.log_audit_rotationtime = rtime;
dc8c34
 		runit = loginfo.log_audit_rotationunit;
dc8c34
 		break;
dc8c34
-	   default:
dc8c34
-		rv = 1;
dc8c34
 	}
dc8c34
 
dc8c34
 	/* find out the rotation unit we have se right now */
dc8c34
@@ -1151,19 +1145,17 @@ log_set_rotationtime(const char *attrname, char *rtime_str, int logtype, char *r
dc8c34
 		 fe_cfg->accesslog_rotationtime = rtime;
dc8c34
 		 loginfo.log_access_rotationtime_secs = value;
dc8c34
 		 LOG_ACCESS_UNLOCK_WRITE();
dc8c34
-		break;
dc8c34
+		 break;
dc8c34
 	   case SLAPD_ERROR_LOG:
dc8c34
 		 fe_cfg->errorlog_rotationtime = rtime;
dc8c34
-		loginfo.log_error_rotationtime_secs = value;
dc8c34
-		LOG_ERROR_UNLOCK_WRITE();
dc8c34
-		break;
dc8c34
+		 loginfo.log_error_rotationtime_secs = value;
dc8c34
+		 LOG_ERROR_UNLOCK_WRITE();
dc8c34
+		 break;
dc8c34
 	   case SLAPD_AUDIT_LOG:
dc8c34
 		 fe_cfg->auditlog_rotationtime = rtime;
dc8c34
-		loginfo.log_audit_rotationtime_secs = value;
dc8c34
-		LOG_AUDIT_UNLOCK_WRITE();
dc8c34
-		break;
dc8c34
-	   default:
dc8c34
-		rv = 1;
dc8c34
+		 loginfo.log_audit_rotationtime_secs = value;
dc8c34
+		 LOG_AUDIT_UNLOCK_WRITE();
dc8c34
+		 break;
dc8c34
 	}
dc8c34
 	return rv;
dc8c34
 }
dc8c34
@@ -1219,8 +1211,6 @@ int log_set_rotationtimeunit(const char *attrname, char *runit, int logtype, cha
dc8c34
 	LOG_AUDIT_LOCK_WRITE( );
dc8c34
 	origvalue = loginfo.log_audit_rotationtime;
dc8c34
 	break;
dc8c34
-  default:
dc8c34
-	rv = 1;
dc8c34
   }
dc8c34
   
dc8c34
   if (strcasecmp(runit, "month") == 0) {
dc8c34
@@ -1270,8 +1260,6 @@ int log_set_rotationtimeunit(const char *attrname, char *runit, int logtype, cha
dc8c34
 	fe_cfg->auditlog_rotationunit = slapi_ch_strdup ( runit );
dc8c34
 	LOG_AUDIT_UNLOCK_WRITE();
dc8c34
 	break;
dc8c34
-  default:
dc8c34
-	rv = 1;
dc8c34
   }
dc8c34
   return rv;
dc8c34
 }
dc8c34
@@ -1321,9 +1309,6 @@ log_set_maxdiskspace(const char *attrname, char *maxdiskspace_str, int logtype,
dc8c34
 		LOG_AUDIT_LOCK_WRITE( );
dc8c34
 		mlogsize = loginfo.log_audit_maxlogsize;
dc8c34
 		break;
dc8c34
-	   default:
dc8c34
-		rv = 1;
dc8c34
-		mlogsize = -1;
dc8c34
 	}
dc8c34
 	maxdiskspace = (PRInt64)s_maxdiskspace * LOG_MB_IN_BYTES;
dc8c34
 	if (maxdiskspace < 0) {
dc8c34
@@ -1357,11 +1342,6 @@ log_set_maxdiskspace(const char *attrname, char *maxdiskspace_str, int logtype,
dc8c34
 		}
dc8c34
 		LOG_AUDIT_UNLOCK_WRITE();
dc8c34
 		break;
dc8c34
-	   default:
dc8c34
-		 PR_snprintf( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, 
dc8c34
-			"%s: invalid log type (%d) for setting maximum disk space: %d MB\n",
dc8c34
-			attrname, logtype, s_maxdiskspace);
dc8c34
-		 rv = LDAP_OPERATIONS_ERROR;
dc8c34
 	}
dc8c34
 	return rv;
dc8c34
 
dc8c34
@@ -1581,10 +1561,6 @@ log_set_expirationtimeunit(const char *attrname, char *expunit, int logtype, cha
dc8c34
 		rsecs = loginfo.log_audit_rotationtime_secs;
dc8c34
 		exptimeunitp = &(loginfo.log_audit_exptimeunit);
dc8c34
 		break;
dc8c34
-	   default:
dc8c34
-		rv = 1;
dc8c34
-		exptime = -1;
dc8c34
-		rsecs = -1;
dc8c34
 	}
dc8c34
 
dc8c34
 	value = -1;
dc8c34
@@ -1634,8 +1610,6 @@ log_set_expirationtimeunit(const char *attrname, char *expunit, int logtype, cha
dc8c34
 		fe_cfg->auditlog_exptimeunit = slapi_ch_strdup ( expunit );
dc8c34
 		LOG_AUDIT_UNLOCK_WRITE();
dc8c34
 		break;
dc8c34
-	   default:
dc8c34
-		rv = 1;
dc8c34
 	}
dc8c34
 
dc8c34
 	return rv;
dc8c34
@@ -1756,8 +1730,8 @@ slapd_log_audit_proc (
dc8c34
 	char	*buffer,
dc8c34
 	int	buf_len)
dc8c34
 {
dc8c34
-	int err;
dc8c34
 	if ( (loginfo.log_audit_state & LOGGING_ENABLED) && (loginfo.log_audit_file != NULL) ){
dc8c34
+		int err;
dc8c34
 		LOG_AUDIT_LOCK_WRITE( );
dc8c34
 		if (log__needrotation(loginfo.log_audit_fdes,
dc8c34
 					SLAPD_AUDIT_LOG) == LOG_ROTATE) {
dc8c34
@@ -4176,9 +4150,9 @@ static void log_append_buffer2(time_t tnl, LogBufferInfo *lbi, char *msg1, size_
dc8c34
 static void log_flush_buffer(LogBufferInfo *lbi, int type, int sync_now)
dc8c34
 {
dc8c34
 	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
-	int err = 0;
dc8c34
-	
dc8c34
+
dc8c34
     if (type == SLAPD_ACCESS_LOG) {
dc8c34
+        int err = 0;
dc8c34
 
dc8c34
 		/* It is only safe to flush once any other threads which are copying are finished */
dc8c34
 		while (lbi->refcount > 0) {
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34