andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 6 months ago
Clone
dc8c34
From dd6f95cfdb5d95d6a2abba57082ef94206abab37 Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Thu, 6 Jun 2013 11:28:07 -0400
dc8c34
Subject: [PATCH 93/99] Coverity Fixes (Part 5)
dc8c34
dc8c34
11784 - Deference before null check (uiduniq/uid.c)
dc8c34
11785 - Deference before null check (conntable.c)
dc8c34
11786 - Deference before null check (opshared.c)
dc8c34
11787 - Deference before null check (tools/dbscan.c)
dc8c34
11788 - Deference before null check (tools/dbscan.c)
dc8c34
11789 - Deference before null check (tools/dbscan.c)
dc8c34
11790 - Allocation size mismatch (idl.c)
dc8c34
11791 - Allocation size mismatch (idl.c)
dc8c34
11792 - Wrong sizeof argument (dna.c)
dc8c34
11793 - Stray semicolon (lib/base/util.c)
dc8c34
11794 - Stray semicolon (lib/base/util.c)
dc8c34
11795 - Destination buffer too small (log.c)
dc8c34
11809 - Use after free (repl5_mtnode_ext.c)
dc8c34
11849 - Unitialized sclara variable (dblayer.c)
dc8c34
dc8c34
https://bugzilla.redhat.com/show_bug.cgi?id=970221
dc8c34
dc8c34
Reviewed by: richm(Thanks!!)
dc8c34
(cherry picked from commit 6d23891a44fd41aa0580cdc223667f0ca2b9e1cc)
dc8c34
(cherry picked from commit 9ac276a838636326811284a28695c0fdea4a8d03)
dc8c34
---
dc8c34
 ldap/servers/plugins/dna/dna.c                     |  2 +-
dc8c34
 .../servers/plugins/replication/repl5_mtnode_ext.c |  6 ++-
dc8c34
 ldap/servers/plugins/uiduniq/uid.c                 |  2 +-
dc8c34
 ldap/servers/slapd/back-ldbm/idl.c                 |  4 +-
dc8c34
 ldap/servers/slapd/conntable.c                     |  4 +-
dc8c34
 ldap/servers/slapd/log.c                           | 54 +++++++++++-----------
dc8c34
 ldap/servers/slapd/opshared.c                      |  4 +-
dc8c34
 ldap/servers/slapd/tools/dbscan.c                  | 15 +++---
dc8c34
 lib/base/util.cpp                                  |  2 +-
dc8c34
 9 files changed, 44 insertions(+), 49 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
dc8c34
index 958a4a7..f7e1004 100644
dc8c34
--- a/ldap/servers/plugins/dna/dna.c
dc8c34
+++ b/ldap/servers/plugins/dna/dna.c
dc8c34
@@ -1865,7 +1865,7 @@ dna_first_free_value(struct configEntry *config_entry,
dc8c34
     } else {
dc8c34
         /* This is a single-type range, so just use the first (only)
dc8c34
          * type from the list. */
dc8c34
-        ctrls = (LDAPControl **)slapi_ch_calloc(2, sizeof(LDAPControl));
dc8c34
+        ctrls = (LDAPControl **)slapi_ch_calloc(2, sizeof(LDAPControl *));
dc8c34
         if (NULL == ctrls)
dc8c34
             return LDAP_OPERATIONS_ERROR;
dc8c34
 
dc8c34
diff --git a/ldap/servers/plugins/replication/repl5_mtnode_ext.c b/ldap/servers/plugins/replication/repl5_mtnode_ext.c
dc8c34
index dd0d261..9b61920 100644
dc8c34
--- a/ldap/servers/plugins/replication/repl5_mtnode_ext.c
dc8c34
+++ b/ldap/servers/plugins/replication/repl5_mtnode_ext.c
dc8c34
@@ -110,8 +110,10 @@ multimaster_mtnode_construct_replicas ()
dc8c34
             ext->replica = object_new(r, replica_destroy);
dc8c34
             if (replica_add_by_name (replica_get_name (r), ext->replica) != 0)
dc8c34
             {
dc8c34
-                object_release (ext->replica);    
dc8c34
-                ext->replica = NULL;
dc8c34
+                if(ext->replica){
dc8c34
+                    object_release (ext->replica);
dc8c34
+                    ext->replica = NULL;
dc8c34
+                }
dc8c34
             }
dc8c34
         }
dc8c34
 	}
dc8c34
diff --git a/ldap/servers/plugins/uiduniq/uid.c b/ldap/servers/plugins/uiduniq/uid.c
dc8c34
index d9e6ba4..984b93e 100644
dc8c34
--- a/ldap/servers/plugins/uiduniq/uid.c
dc8c34
+++ b/ldap/servers/plugins/uiduniq/uid.c
dc8c34
@@ -509,7 +509,7 @@ findSubtreeAndSearch(Slapi_DN *parentDN, const char *attrName, Slapi_Attr *attr,
dc8c34
   Slapi_DN *newpar = NULL;
dc8c34
 
dc8c34
   slapi_sdn_get_parent(parentDN, curpar);
dc8c34
-  while ((curpar != NULL) && (slapi_sdn_get_dn(curpar) != NULL))
dc8c34
+  while (slapi_sdn_get_dn(curpar) != NULL)
dc8c34
   {
dc8c34
         if ((spb = dnHasObjectClass(curpar, markerObjectClass)))
dc8c34
         {
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/idl.c b/ldap/servers/slapd/back-ldbm/idl.c
dc8c34
index 58736f8..76ee252 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/idl.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/idl.c
dc8c34
@@ -1247,7 +1247,7 @@ void idl_insert(IDList **idl, ID id)
dc8c34
         (*idl)->b_nmax *= 2;
dc8c34
 
dc8c34
         (*idl) = (IDList *) slapi_ch_realloc( (char *) (*idl),
dc8c34
-                                            ((*idl)->b_nmax + 2) * sizeof(ID) );
dc8c34
+                                            ((*idl)->b_nmax + 2) * sizeof(ID) + sizeof(IDList) );
dc8c34
     }
dc8c34
 
dc8c34
     /* make a slot for the new id */
dc8c34
@@ -1345,7 +1345,7 @@ idl_insert_maxids( IDList **idl, ID id, int maxids )
dc8c34
 			(*idl)->b_nmax = maxids;
dc8c34
 		}
dc8c34
 		*idl = (IDList *) slapi_ch_realloc( (char *) *idl,
dc8c34
-		    ((*idl)->b_nmax + 2) * sizeof(ID) );
dc8c34
+		    ((*idl)->b_nmax + 2) * sizeof(ID) + sizeof(IDList));
dc8c34
 	}
dc8c34
 
dc8c34
 	/* make a slot for the new id */
dc8c34
diff --git a/ldap/servers/slapd/conntable.c b/ldap/servers/slapd/conntable.c
dc8c34
index df4f2f8..7cf9f31 100644
dc8c34
--- a/ldap/servers/slapd/conntable.c
dc8c34
+++ b/ldap/servers/slapd/conntable.c
dc8c34
@@ -444,9 +444,7 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e)
dc8c34
 			val.bv_val = bufptr;
dc8c34
 			val.bv_len = strlen( bufptr );
dc8c34
 			attrlist_merge( &e->e_attrs, "connection", vals );
dc8c34
-			if (newbuf) {
dc8c34
-				slapi_ch_free_string(&newbuf);
dc8c34
-			}
dc8c34
+			slapi_ch_free_string(&newbuf);
dc8c34
 		}
dc8c34
 		PR_Unlock( ct->c[i].c_mutex );
dc8c34
 	}
dc8c34
diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
dc8c34
index 72a918b..c6131fb 100644
dc8c34
--- a/ldap/servers/slapd/log.c
dc8c34
+++ b/ldap/servers/slapd/log.c
dc8c34
@@ -2058,7 +2058,7 @@ static int vslapd_log_access(char *fmt, va_list ap)
dc8c34
     int		blen, vlen;
dc8c34
     /* info needed to keep us from calling localtime/strftime so often: */
dc8c34
     static time_t	old_time = 0;
dc8c34
-    static char		old_tbuf[TBUFSIZE];
dc8c34
+    static char		old_tbuf[SLAPI_LOG_BUFSIZ];
dc8c34
 	static int old_blen = 0;
dc8c34
 
dc8c34
     tnl = current_time();
dc8c34
@@ -2066,11 +2066,11 @@ static int vslapd_log_access(char *fmt, va_list ap)
dc8c34
     /* check if we can use the old strftime buffer */
dc8c34
     PR_Lock(ts_time_lock);
dc8c34
     if (tnl == old_time) {
dc8c34
-	strcpy(buffer, old_tbuf);
dc8c34
-	blen = old_blen;
dc8c34
-	PR_Unlock(ts_time_lock);
dc8c34
+        strcpy(buffer, old_tbuf);
dc8c34
+        blen = old_blen;
dc8c34
+        PR_Unlock(ts_time_lock);
dc8c34
     } else {
dc8c34
-	/* nope... painstakingly create the new strftime buffer */
dc8c34
+    /* nope... painstakingly create the new strftime buffer */
dc8c34
 #ifdef _WIN32
dc8c34
         {
dc8c34
             struct tm *pt = localtime( &tnl );
dc8c34
@@ -2078,39 +2078,39 @@ static int vslapd_log_access(char *fmt, va_list ap)
dc8c34
             memcpy(&tms, pt, sizeof(struct tm) );
dc8c34
         }
dc8c34
 #else
dc8c34
-	(void)localtime_r( &tnl, &tms );
dc8c34
-	tmsp = &tm;;
dc8c34
+        (void)localtime_r( &tnl, &tms );
dc8c34
+        tmsp = &tm;;
dc8c34
 #endif
dc8c34
 
dc8c34
 #ifdef BSD_TIME
dc8c34
-	tz = tmsp->tm_gmtoff;
dc8c34
+        tz = tmsp->tm_gmtoff;
dc8c34
 #else /* BSD_TIME */
dc8c34
-	tz = - timezone;
dc8c34
-	if ( tmsp->tm_isdst ) {
dc8c34
-	    tz += 3600;
dc8c34
-	}
dc8c34
+        tz = - timezone;
dc8c34
+        if ( tmsp->tm_isdst ) {
dc8c34
+            tz += 3600;
dc8c34
+	    }
dc8c34
 #endif /* BSD_TIME */
dc8c34
-	sign = ( tz >= 0 ? '+' : '-' );
dc8c34
-	if ( tz < 0 ) {
dc8c34
-	    tz = -tz;
dc8c34
-	}
dc8c34
-	(void)strftime( tbuf, (size_t)TBUFSIZE, "%d/%b/%Y:%H:%M:%S", tmsp);
dc8c34
-	sprintf( buffer, "[%s %c%02d%02d] ", tbuf, sign, 
dc8c34
-		 (int)( tz / 3600 ), (int)( tz % 3600));
dc8c34
-	old_time = tnl;
dc8c34
-	strcpy(old_tbuf, buffer);
dc8c34
-	blen = strlen(buffer);
dc8c34
-	old_blen = blen;
dc8c34
-	PR_Unlock(ts_time_lock);
dc8c34
+        sign = ( tz >= 0 ? '+' : '-' );
dc8c34
+        if ( tz < 0 ) {
dc8c34
+            tz = -tz;
dc8c34
+        }
dc8c34
+        (void)strftime( tbuf, (size_t)TBUFSIZE, "%d/%b/%Y:%H:%M:%S", tmsp);
dc8c34
+        sprintf( buffer, "[%s %c%02d%02d] ", tbuf, sign,
dc8c34
+                (int)( tz / 3600 ), (int)( tz % 3600));
dc8c34
+        old_time = tnl;
dc8c34
+        strcpy(old_tbuf, buffer);
dc8c34
+        blen = strlen(buffer);
dc8c34
+        old_blen = blen;
dc8c34
+        PR_Unlock(ts_time_lock);
dc8c34
     }
dc8c34
 
dc8c34
-	vlen = PR_vsnprintf(vbuf, SLAPI_LOG_BUFSIZ, fmt, ap);
dc8c34
+    vlen = PR_vsnprintf(vbuf, SLAPI_LOG_BUFSIZ, fmt, ap);
dc8c34
     if (! vlen) {
dc8c34
-		return -1;
dc8c34
+        return -1;
dc8c34
     }
dc8c34
     
dc8c34
     if (SLAPI_LOG_BUFSIZ - blen < vlen) {
dc8c34
-		return -1;
dc8c34
+        return -1;
dc8c34
     }
dc8c34
 
dc8c34
     log_append_buffer2(tnl, loginfo.log_access_buffer, buffer, blen, vbuf, vlen);    
dc8c34
diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c
dc8c34
index a96b950..1689283 100644
dc8c34
--- a/ldap/servers/slapd/opshared.c
dc8c34
+++ b/ldap/servers/slapd/opshared.c
dc8c34
@@ -1090,9 +1090,7 @@ process_entry(Slapi_PBlock *pb, Slapi_Entry *e, int send_result)
dc8c34
                 ber_bvecfree(refscopy);
dc8c34
                 refscopy = NULL;
dc8c34
             }
dc8c34
-            if( NULL != tmpUrls) {
dc8c34
-                slapi_ch_free( (void **)&tmpUrls );
dc8c34
-            }
dc8c34
+            slapi_ch_free( (void **)&tmpUrls );
dc8c34
         }
dc8c34
 
dc8c34
         return 1;        /* done with this entry */
dc8c34
diff --git a/ldap/servers/slapd/tools/dbscan.c b/ldap/servers/slapd/tools/dbscan.c
dc8c34
index 6b0f525..d84f138 100644
dc8c34
--- a/ldap/servers/slapd/tools/dbscan.c
dc8c34
+++ b/ldap/servers/slapd/tools/dbscan.c
dc8c34
@@ -825,10 +825,9 @@ display_entryrdn_self(DB *db, ID id, const char *nrdn, int indent)
dc8c34
     display_entryrdn_children(db, id_stored_to_internal(elem->rdn_elem_id),
dc8c34
                               elem->rdn_elem_nrdn_rdn, indent);
dc8c34
 bail:
dc8c34
-    if (keybuf) {
dc8c34
-        free(keybuf);
dc8c34
-    }
dc8c34
+    free(keybuf);
dc8c34
     cursor->c_close(cursor);
dc8c34
+
dc8c34
     return;
dc8c34
 }
dc8c34
 
dc8c34
@@ -866,10 +865,9 @@ display_entryrdn_parent(DB *db, ID id, const char *nrdn, int indent)
dc8c34
     elem = (rdn_elem *)data.data;
dc8c34
     _entryrdn_dump_rdn_elem(keybuf, elem, indent);
dc8c34
 bail:
dc8c34
-    if (keybuf) {
dc8c34
-        free(keybuf);
dc8c34
-    }
dc8c34
+    free(keybuf);
dc8c34
     cursor->c_close(cursor);
dc8c34
+
dc8c34
     return;
dc8c34
 }
dc8c34
 
dc8c34
@@ -939,10 +937,9 @@ display_entryrdn_children(DB *db, ID id, const char *nrdn, int indent)
dc8c34
         }
dc8c34
     }
dc8c34
 bail:
dc8c34
-    if (keybuf) {
dc8c34
-        free(keybuf);
dc8c34
-    }
dc8c34
+    free(keybuf);
dc8c34
     cursor->c_close(cursor);
dc8c34
+
dc8c34
     return;
dc8c34
 }
dc8c34
 
dc8c34
diff --git a/lib/base/util.cpp b/lib/base/util.cpp
dc8c34
index b198154..01f916d 100644
dc8c34
--- a/lib/base/util.cpp
dc8c34
+++ b/lib/base/util.cpp
dc8c34
@@ -253,7 +253,7 @@ static char *Bfmt[] = {
dc8c34
 
dc8c34
 static void _util_strftime_conv(char *, int, int, char);
dc8c34
 
dc8c34
-#define _util_strftime_add(str) for (;(*pt = *str++); pt++);
dc8c34
+#define _util_strftime_add(str) for (;(*pt = *str++); pt++)
dc8c34
 #define _util_strftime_copy(str, len) memcpy(pt, str, len); pt += len;
dc8c34
 #define _util_strftime_fmt util_strftime
dc8c34
 
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34