andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From f167a9e8a462c1b5deb7e5a3c36b989672e0fd0b Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Fri, 7 Jun 2013 11:15:27 -0400
dc8c34
Subject: [PATCH 94/99] Fri Jun 7 10:41:00 2013 -0400
dc8c34
dc8c34
    Coverity Fixes (Part 6)
dc8c34
dc8c34
    11611 - Unchecked value (main.c)
dc8c34
    11671 - Copy-paste error (cb_instance.c)
dc8c34
    11704 - Dereference after null check (repl5_replica_config.c)
dc8c34
    11766 - Resource leak (dblayer.c)
dc8c34
    11873 - Argument can not be negative (ldclt/data.c)
dc8c34
    Jenkins error:  mmldif.c
dc8c34
    11876 - Deference before null check (cl5_clcache.c)
dc8c34
dc8c34
    https://bugzilla.redhat.com/show_bug.cgi?id=970221
dc8c34
dc8c34
    Reviewed by: Rich(Thanks!)
dc8c34
(cherry picked from commit 4a0199b3c3a73b094a7bff64404a632c3bfe7072)
dc8c34
(cherry picked from commit 8212d48b57adf223c7022dba4fbdb70e7aa2080e)
dc8c34
---
dc8c34
 ldap/servers/plugins/chainingdb/cb_instance.c           |  2 +-
dc8c34
 ldap/servers/plugins/replication/cl5_clcache.c          |  4 +---
dc8c34
 ldap/servers/plugins/replication/repl5_replica_config.c |  3 ++-
dc8c34
 ldap/servers/slapd/back-ldbm/dblayer.c                  | 10 +++++-----
dc8c34
 ldap/servers/slapd/main.c                               |  7 +++++--
dc8c34
 ldap/servers/slapd/tools/ldclt/data.c                   | 17 ++++++++++-------
dc8c34
 ldap/servers/slapd/tools/mmldif.c                       |  2 +-
dc8c34
 7 files changed, 25 insertions(+), 20 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_instance.c b/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
index 8fb694a..95781b5 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
@@ -1437,7 +1437,7 @@ static int cb_instance_bindmech_set(void *arg, void *value, char *errorbuf, int
dc8c34
 			    charray_add(&inst->pool->waste_basket,inst->pool->mech);
dc8c34
 			}
dc8c34
 			if (inst->bind_pool->mech) {
dc8c34
-			    charray_add(&inst->pool->waste_basket,inst->bind_pool->mech);
dc8c34
+			    charray_add(&inst->bind_pool->waste_basket,inst->bind_pool->mech);
dc8c34
 			}
dc8c34
 			rc=CB_REOPEN_CONN;
dc8c34
 		}
dc8c34
diff --git a/ldap/servers/plugins/replication/cl5_clcache.c b/ldap/servers/plugins/replication/cl5_clcache.c
dc8c34
index 67e64f5..7a6a446 100644
dc8c34
--- a/ldap/servers/plugins/replication/cl5_clcache.c
dc8c34
+++ b/ldap/servers/plugins/replication/cl5_clcache.c
dc8c34
@@ -752,9 +752,7 @@ clcache_skip_change ( CLC_Buffer *buf )
dc8c34
 			 (csn_get_seqnum(buf->buf_current_csn) ==
dc8c34
 				csn_get_seqnum(cscb->local_maxcsn) + 1) )
dc8c34
 		{
dc8c34
-			if(cscb->local_maxcsn){
dc8c34
-				csn_init_by_csn ( cscb->local_maxcsn, buf->buf_current_csn );
dc8c34
-			}
dc8c34
+			csn_init_by_csn ( cscb->local_maxcsn, buf->buf_current_csn );
dc8c34
 			if(cscb->consumer_maxcsn){
dc8c34
 				csn_init_by_csn ( cscb->consumer_maxcsn, buf->buf_current_csn );
dc8c34
 			}
dc8c34
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
index 5ca7706..0b72bec 100644
dc8c34
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
@@ -2352,7 +2352,7 @@ delete_aborted_rid(Replica *r, ReplicaId rid, char *repl_root, int skip){
dc8c34
 static void
dc8c34
 delete_cleaned_rid_config(cleanruv_data *clean_data)
dc8c34
 {
dc8c34
-    Slapi_PBlock *pb = slapi_pblock_new();
dc8c34
+    Slapi_PBlock *pb;
dc8c34
     Slapi_Entry **entries = NULL;
dc8c34
     LDAPMod *mods[2];
dc8c34
     LDAPMod mod;
dc8c34
@@ -2381,6 +2381,7 @@ delete_cleaned_rid_config(cleanruv_data *clean_data)
dc8c34
     /*
dc8c34
      *  Search the config for the exact attribute value to delete
dc8c34
      */
dc8c34
+    pb = slapi_pblock_new();
dc8c34
     dn = replica_get_dn(clean_data->replica);
dc8c34
     slapi_search_internal_set_pb(pb, dn, LDAP_SCOPE_SUBTREE, "nsds5ReplicaCleanRUV=*", NULL, 0, NULL, NULL,
dc8c34
         (void *)plugin_get_default_component_id(), 0);
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
dc8c34
index cb8ef68..fab61f3 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
dc8c34
@@ -2996,6 +2996,8 @@ dblayer_open_file(backend *be, char* indexname, int open_flag,
dc8c34
     int return_value = 0;
dc8c34
     DB *dbp = NULL;
dc8c34
     char *subname = NULL;
dc8c34
+    char inst_dir[MAXPATHLEN];
dc8c34
+    char *inst_dirp = NULL;
dc8c34
 
dc8c34
     PR_ASSERT(NULL != li);
dc8c34
     priv = (dblayer_private*)li->li_dblayer_private;
dc8c34
@@ -3059,8 +3061,6 @@ dblayer_open_file(backend *be, char* indexname, int open_flag,
dc8c34
                            inst->inst_parent_dir_name) > 0) &&
dc8c34
         !dblayer_inst_exists(inst, file_name))
dc8c34
     {
dc8c34
-        char inst_dir[MAXPATHLEN];
dc8c34
-        char *inst_dirp = NULL;
dc8c34
         char *abs_file_name = NULL;
dc8c34
         /* create a file with abs path, then try again */
dc8c34
 
dc8c34
@@ -3072,9 +3072,6 @@ dblayer_open_file(backend *be, char* indexname, int open_flag,
dc8c34
         }
dc8c34
         abs_file_name = slapi_ch_smprintf("%s%c%s",
dc8c34
                 inst_dirp, get_sep(inst_dirp), file_name);
dc8c34
-        if (inst_dirp != inst_dir){
dc8c34
-            slapi_ch_free_string(&inst_dirp);
dc8c34
-        }
dc8c34
         DB_OPEN(pENV->dblayer_openflags,
dc8c34
                 dbp, NULL/* txnid */, abs_file_name, subname, DB_BTREE,
dc8c34
                 open_flags, priv->dblayer_file_mode, return_value);
dc8c34
@@ -3107,6 +3104,9 @@ dblayer_open_file(backend *be, char* indexname, int open_flag,
dc8c34
 out:
dc8c34
     slapi_ch_free((void**)&file_name);
dc8c34
     slapi_ch_free((void**)&rel_path);
dc8c34
+    if (inst_dirp != inst_dir){
dc8c34
+        slapi_ch_free_string(&inst_dirp);
dc8c34
+    }
dc8c34
     /* close the database handle to avoid handle leak */
dc8c34
     if (dbp && (return_value != 0)) {
dc8c34
         dblayer_close_file(dbp);
dc8c34
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
dc8c34
index 9938c01..53cb5c8 100644
dc8c34
--- a/ldap/servers/slapd/main.c
dc8c34
+++ b/ldap/servers/slapd/main.c
dc8c34
@@ -232,7 +232,10 @@ chown_dir_files(char *name, struct passwd *pw, PRBool strip_fn, PRBool both)
dc8c34
     if((ptr=strrchr(log,'/'))==NULL)
dc8c34
     {
dc8c34
       LDAPDebug(LDAP_DEBUG_ANY, "Caution changing ownership of ./%s \n",name,0,0);
dc8c34
-      slapd_chown_if_not_owner(log, pw->pw_uid, -1 ); 
dc8c34
+      if(slapd_chown_if_not_owner(log, pw->pw_uid, -1 )){
dc8c34
+          LDAPDebug(LDAP_DEBUG_ANY, "chown_dir_files: file (%s) chown failed (%d) %s.\n",
dc8c34
+                  log, errno, slapd_system_strerror(errno));
dc8c34
+      }
dc8c34
       rc=1;
dc8c34
     } else if(log==ptr) {
dc8c34
       LDAPDebug(LDAP_DEBUG_ANY, "Caution changing ownership of / directory and its contents to %s\n",pw->pw_name,0,0);
dc8c34
@@ -247,7 +250,7 @@ chown_dir_files(char *name, struct passwd *pw, PRBool strip_fn, PRBool both)
dc8c34
     while( (entry = PR_ReadDir(dir , PR_SKIP_BOTH )) !=NULL ) 
dc8c34
     {
dc8c34
       PR_snprintf(file,MAXPATHLEN+1,"%s/%s",log,entry->name);
dc8c34
-      if((rc = slapd_chown_if_not_owner( file, pw->pw_uid, both?pw->pw_gid:-1 )) != 0){
dc8c34
+      if(slapd_chown_if_not_owner( file, pw->pw_uid, both?pw->pw_gid:-1 )){
dc8c34
     	  LDAPDebug(LDAP_DEBUG_ANY, "chown_dir_files: file (%s) chown failed (%d) %s.\n",
dc8c34
     			  file, errno, slapd_system_strerror(errno));
dc8c34
       }
dc8c34
diff --git a/ldap/servers/slapd/tools/ldclt/data.c b/ldap/servers/slapd/tools/ldclt/data.c
dc8c34
index f6dd4ef..45016d8 100644
dc8c34
--- a/ldap/servers/slapd/tools/ldclt/data.c
dc8c34
+++ b/ldap/servers/slapd/tools/ldclt/data.c
dc8c34
@@ -143,7 +143,7 @@ int loadImages (
dc8c34
   char		*fileName;	/* As read from the system */
dc8c34
   char		 name [1024];	/* To build the full path */
dc8c34
   struct stat	 stat_buf;	/* To read the image size */
dc8c34
-  int		 fd;		/* To open the image */
dc8c34
+  int		 fd = -1;		/* To open the image */
dc8c34
   int		 ret;		/* Return value */
dc8c34
   int		 rc = 0;
dc8c34
 
dc8c34
@@ -303,11 +303,13 @@ int loadImages (
dc8c34
        */
dc8c34
       if (close (fd) < 0)
dc8c34
       {
dc8c34
-	perror (name);
dc8c34
-	fprintf (stderr, "Cannot close(%s)\n", name);
dc8c34
-	fflush (stderr);
dc8c34
-	rc = -1;
dc8c34
-	goto exit;
dc8c34
+          perror (name);
dc8c34
+          fprintf (stderr, "Cannot close(%s)\n", name);
dc8c34
+          fflush (stderr);
dc8c34
+          rc = -1;
dc8c34
+          goto exit;
dc8c34
+      } else {
dc8c34
+          fd = -1;
dc8c34
       }
dc8c34
     }
dc8c34
 #ifdef _WIN32
dc8c34
@@ -335,7 +337,8 @@ exit:
dc8c34
 #ifdef _WIN32
dc8c34
   if (findPath) free (findPath);
dc8c34
 #endif
dc8c34
-  close(fd);
dc8c34
+  if(fd != -1)
dc8c34
+      close(fd);
dc8c34
 
dc8c34
   return rc;
dc8c34
 }
dc8c34
diff --git a/ldap/servers/slapd/tools/mmldif.c b/ldap/servers/slapd/tools/mmldif.c
dc8c34
index fb97129..1f01976 100644
dc8c34
--- a/ldap/servers/slapd/tools/mmldif.c
dc8c34
+++ b/ldap/servers/slapd/tools/mmldif.c
dc8c34
@@ -729,7 +729,7 @@ readrec(edfFILE * edf1, attrib1_t ** attrib)
dc8c34
     int	toolong = FALSE;
dc8c34
     int	rc;
dc8c34
     int cmp;
dc8c34
-    attrib1_t *	att;
dc8c34
+    attrib1_t *	att = NULL;
dc8c34
     attrib1_t **	prev;
dc8c34
     attrib1_t *	freelist = *attrib;
dc8c34
     attrib1_t *	newlist = NULL;
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34