Blame SOURCES/0002-Ticket-49385-Fix-coverity-warnings.patch

96373c
From 8308e20075adacfdf1827aaa3230e503207832bc Mon Sep 17 00:00:00 2001
96373c
From: Mark Reynolds <mreynolds@redhat.com>
96373c
Date: Mon, 2 Oct 2017 09:33:29 -0400
96373c
Subject: [PATCH] Ticket 49385 - Fix coverity warnings
96373c
96373c
Description:  This fixes coverity issues found from RHEL build of 1.3.7
96373c
96373c
https://pagure.io/389-ds-base/issue/49385
96373c
96373c
Reviewed by: lkrispenz(Thanks!)
96373c
96373c
(cherry picked from commit 805e8f4d3016eb9c7906c1416482047a234d51ba)
96373c
---
96373c
 ldap/servers/plugins/http/http_impl.c    |  1 +
96373c
 ldap/servers/plugins/replication/urp.c   | 10 ++++++----
96373c
 ldap/servers/plugins/syntaxes/string.c   |  1 +
96373c
 ldap/servers/slapd/back-ldbm/dbversion.c |  2 +-
96373c
 ldap/servers/slapd/back-ldbm/index.c     |  1 +
96373c
 ldap/servers/slapd/conntable.c           |  2 +-
96373c
 ldap/servers/slapd/modify.c              |  1 +
96373c
 ldap/servers/slapd/plugin.c              |  3 ++-
96373c
 ldap/servers/slapd/referral.c            | 18 +++++++++---------
96373c
 ldap/servers/slapd/task.c                |  8 ++++++--
96373c
 ldap/servers/snmp/main.c                 | 13 +++++++++++--
96373c
 11 files changed, 40 insertions(+), 20 deletions(-)
96373c
96373c
diff --git a/ldap/servers/plugins/http/http_impl.c b/ldap/servers/plugins/http/http_impl.c
96373c
index d8bbe38..350c839 100644
96373c
--- a/ldap/servers/plugins/http/http_impl.c
96373c
+++ b/ldap/servers/plugins/http/http_impl.c
96373c
@@ -601,6 +601,7 @@ sendPostReq(PRFileDesc *fd, const char *path, httpheader **httpheaderArray, char
96373c
     if (path) {
96373c
         path_len = strlen(path);
96373c
     } else {
96373c
+        path = "";
96373c
         path_len = 0;
96373c
     }
96373c
 
96373c
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
96373c
index 3d63c64..9534c03 100644
96373c
--- a/ldap/servers/plugins/replication/urp.c
96373c
+++ b/ldap/servers/plugins/replication/urp.c
96373c
@@ -856,7 +856,7 @@ urp_post_delete_operation(Slapi_PBlock *pb)
96373c
 static int
96373c
 urp_fixup_add_cenotaph (Slapi_PBlock *pb, char *sessionid, CSN *opcsn)
96373c
 {
96373c
-    Slapi_PBlock *add_pb = slapi_pblock_new();
96373c
+    Slapi_PBlock *add_pb;
96373c
     Slapi_Entry *cenotaph = NULL;
96373c
     Slapi_Entry *pre_entry = NULL;
96373c
     int ret = 0;
96373c
@@ -886,6 +886,7 @@ urp_fixup_add_cenotaph (Slapi_PBlock *pb, char *sessionid, CSN *opcsn)
96373c
     slapi_rdn_remove_attr (rdn, SLAPI_ATTR_UNIQUEID );
96373c
     slapi_rdn_add(rdn, "cenotaphID", uniqueid);
96373c
     newdn = slapi_ch_smprintf("%s,%s", slapi_rdn_get_rdn(rdn), parentdn);
96373c
+    slapi_rdn_free(&rdn;;
96373c
     slapi_ch_free_string(&parentdn);
96373c
     /* slapi_sdn_free(&pre_sdn); */
96373c
 
96373c
@@ -902,6 +903,7 @@ urp_fixup_add_cenotaph (Slapi_PBlock *pb, char *sessionid, CSN *opcsn)
96373c
 
96373c
     slapi_log_err(SLAPI_LOG_REPL, sessionid,
96373c
                    "urp_fixup_add_cenotaph - addinng cenotaph: %s \n", newdn);
96373c
+    add_pb = slapi_pblock_new();
96373c
     slapi_pblock_init(add_pb);
96373c
 
96373c
     slapi_add_entry_internal_set_pb(add_pb,
96373c
@@ -1661,8 +1663,8 @@ urp_conflict_to_glue (char *sessionid, const Slapi_Entry *entry, Slapi_DN *paren
96373c
                            "urp_conflict_to_glue failed(%d) - %s --> %s\n", op_result, basedn, newrdn);
96373c
             rc = 1;
96373c
         }
96373c
-        slapi_ch_free ( (void**)&newrdn );
96373c
     }
96373c
+    slapi_rdn_free(&parentrdn);
96373c
     return rc;
96373c
 }
96373c
 /* 
96373c
@@ -2166,11 +2168,11 @@ mod_objectclass_attr(const char *uniqueid, const Slapi_DN *entrysdn, const Slapi
96373c
 {
96373c
     Slapi_Mods smods;
96373c
     int op_result;
96373c
-    char csnstr[CSN_STRSIZE+1];
96373c
+    char csnstr[CSN_STRSIZE+1] = {0};
96373c
 
96373c
     slapi_mods_init(&smods, 3);
96373c
     slapi_mods_add(&smods, LDAP_MOD_ADD, "objectclass", strlen("ldapsubentry"),"ldapsubentry");
96373c
-    slapi_mods_add(&smods, LDAP_MOD_REPLACE, "conflictcsn", strlen(csnstr),csn_as_string(opcsn, PR_FALSE, csnstr));
96373c
+    slapi_mods_add(&smods, LDAP_MOD_REPLACE, "conflictcsn", CSN_STRSIZE, csn_as_string(opcsn, PR_FALSE, csnstr));
96373c
     op_result = urp_fixup_modify_entry(uniqueid, entrysdn, opcsn, &smods, 0);
96373c
     slapi_mods_done(&smods);
96373c
     if (op_result == LDAP_TYPE_OR_VALUE_EXISTS) {
96373c
diff --git a/ldap/servers/plugins/syntaxes/string.c b/ldap/servers/plugins/syntaxes/string.c
96373c
index f50dc13..e05ca7f 100644
96373c
--- a/ldap/servers/plugins/syntaxes/string.c
96373c
+++ b/ldap/servers/plugins/syntaxes/string.c
96373c
@@ -391,6 +391,7 @@ bailout:
96373c
     if (free_re) {
96373c
         slapi_re_free(re);
96373c
     }
96373c
+    slapi_ch_free_string(&alt;;
96373c
     slapi_ch_free((void **)&tmpbuf); /* NULL is fine */
96373c
     slapi_ch_free((void **)&bigpat); /* NULL is fine */
96373c
 
96373c
diff --git a/ldap/servers/slapd/back-ldbm/dbversion.c b/ldap/servers/slapd/back-ldbm/dbversion.c
96373c
index 01f86f4..5a77abd 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/dbversion.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/dbversion.c
96373c
@@ -159,7 +159,7 @@ dbversion_read(struct ldbminfo *li, const char *directory, char **ldbmversion, c
96373c
         }
96373c
         (void)PR_Close(prfd);
96373c
 
96373c
-        if (*dataversion == NULL) {
96373c
+        if (dataversion == NULL || *dataversion == NULL) {
96373c
             slapi_log_err(SLAPI_LOG_DEBUG, "dbversion_read", "dataversion not present in \"%s\"\n", filename);
96373c
         }
96373c
         if (*ldbmversion == NULL) {
96373c
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
96373c
index 798480e..58b11ed 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/index.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/index.c
96373c
@@ -1063,6 +1063,7 @@ index_read_ext_allids(
96373c
             /* The database might not exist. We have to assume it means empty set */
96373c
             slapi_log_err(SLAPI_LOG_TRACE, "index_read_ext_allids", "Failed to access idl index for %s\n", basetype);
96373c
             slapi_log_err(SLAPI_LOG_TRACE, "index_read_ext_allids", "Assuming %s has no index values\n", basetype);
96373c
+            idl_free(&idl);
96373c
             idl = idl_alloc(0);
96373c
             break;
96373c
         } else {
96373c
diff --git a/ldap/servers/slapd/conntable.c b/ldap/servers/slapd/conntable.c
96373c
index c04ca0f..7c57b47 100644
96373c
--- a/ldap/servers/slapd/conntable.c
96373c
+++ b/ldap/servers/slapd/conntable.c
96373c
@@ -347,7 +347,7 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e)
96373c
 
96373c
         PR_EnterMonitor(ct->c[i].c_mutex);
96373c
         if (ct->c[i].c_sd != SLAPD_INVALID_SOCKET) {
96373c
-            char buf2[20];
96373c
+            char buf2[SLAPI_TIMESTAMP_BUFSIZE+1];
96373c
             size_t lendn = ct->c[i].c_dn ? strlen(ct->c[i].c_dn) : 6; /* "NULLDN" */
96373c
             size_t lenip = ct->c[i].c_ipaddr ? strlen(ct->c[i].c_ipaddr) : 0;
96373c
             size_t lenconn = 1;
96373c
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
96373c
index 4b5a676..6309975 100644
96373c
--- a/ldap/servers/slapd/modify.c
96373c
+++ b/ldap/servers/slapd/modify.c
96373c
@@ -923,6 +923,7 @@ op_shared_modify(Slapi_PBlock *pb, int pw_change, char *old_pw)
96373c
             if (pw_encodevals_ext(pb, sdn, va)) {
96373c
                 slapi_log_err(SLAPI_LOG_CRIT, "op_shared_modify", "Unable to hash userPassword attribute for %s.\n", slapi_entry_get_dn_const(e));
96373c
                 send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, "Unable to store attribute \"userPassword\" correctly\n", 0, NULL);
96373c
+                valuearray_free(&va);
96373c
                 goto free_and_return;
96373c
             }
96373c
 
96373c
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
96373c
index f47ff9b..e02133a 100644
96373c
--- a/ldap/servers/slapd/plugin.c
96373c
+++ b/ldap/servers/slapd/plugin.c
96373c
@@ -4242,7 +4242,7 @@ bail:
96373c
 int
96373c
 slapi_set_plugin_default_config(const char *type, Slapi_Value *value)
96373c
 {
96373c
-    Slapi_PBlock *pb = slapi_pblock_new();
96373c
+    Slapi_PBlock *pb;
96373c
     Slapi_Entry **entries = NULL;
96373c
     int rc = LDAP_SUCCESS;
96373c
     char **search_attrs = NULL; /* used by search */
96373c
@@ -4251,6 +4251,7 @@ slapi_set_plugin_default_config(const char *type, Slapi_Value *value)
96373c
         return rc;
96373c
     }
96373c
 
96373c
+    pb = slapi_pblock_new();
96373c
     charray_add(&search_attrs, slapi_ch_strdup(type));
96373c
 
96373c
     /* cn=plugin default config,cn=config */
96373c
diff --git a/ldap/servers/slapd/referral.c b/ldap/servers/slapd/referral.c
96373c
index c5d9ffc..5935820 100644
96373c
--- a/ldap/servers/slapd/referral.c
96373c
+++ b/ldap/servers/slapd/referral.c
96373c
@@ -153,7 +153,7 @@ referrals_free(void)
96373c
 struct berval **
96373c
 ref_adjust(Slapi_PBlock *pb, struct berval **urls, const Slapi_DN *refsdn, int is_reference)
96373c
 {
96373c
-    int i, len, scope;
96373c
+    int i, len, scope = 0;
96373c
     Slapi_DN *sdn = NULL;
96373c
     char *p, *opdn_norm;
96373c
     struct berval **urlscopy;
96373c
@@ -195,9 +195,9 @@ ref_adjust(Slapi_PBlock *pb, struct berval **urls, const Slapi_DN *refsdn, int i
96373c
 
96373c
     for (i = 0; urls[i] != NULL; ++i) {
96373c
         /*
96373c
-     * duplicate the URL, stripping off the label if there is one and
96373c
-     * leaving extra room for "??base" in case we need to append that.
96373c
-     */
96373c
+         * duplicate the URL, stripping off the label if there is one and
96373c
+         * leaving extra room for "??base" in case we need to append that.
96373c
+         */
96373c
         urlscopy[i] = (struct berval *)slapi_ch_malloc(
96373c
             sizeof(struct berval));
96373c
         if ((p = strchr(urls[i]->bv_val, ' ')) == NULL) {
96373c
@@ -210,16 +210,16 @@ ref_adjust(Slapi_PBlock *pb, struct berval **urls, const Slapi_DN *refsdn, int i
96373c
         urlscopy[i]->bv_val[len] = '\0';
96373c
 
96373c
         /*
96373c
-     * adjust the baseDN as needed and set the length
96373c
-     */
96373c
+         * adjust the baseDN as needed and set the length
96373c
+         */
96373c
         adjust_referral_basedn(&urlscopy[i]->bv_val, refsdn,
96373c
                                opdn_norm, is_reference);
96373c
         urlscopy[i]->bv_len = strlen(urlscopy[i]->bv_val);
96373c
 
96373c
         /*
96373c
-     * if we are dealing with a continuation reference that resulted
96373c
-     * from a one-level search, add a scope of base to the URL.
96373c
-     */
96373c
+         * if we are dealing with a continuation reference that resulted
96373c
+         * from a one-level search, add a scope of base to the URL.
96373c
+         */
96373c
         if (is_reference && operation_get_type(op) == SLAPI_OPERATION_SEARCH &&
96373c
             scope == LDAP_SCOPE_ONELEVEL) {
96373c
             strcat(urlscopy[i]->bv_val, "??base");
96373c
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
96373c
index f3d02d9..53a0af5 100644
96373c
--- a/ldap/servers/slapd/task.c
96373c
+++ b/ldap/servers/slapd/task.c
96373c
@@ -278,6 +278,10 @@ slapi_task_log_notice(Slapi_Task *task, char *format, ...)
96373c
     char buffer[LOG_BUFFER];
96373c
     size_t len;
96373c
 
96373c
+    if (task == NULL) {
96373c
+        return;
96373c
+    }
96373c
+
96373c
     va_start(ap, format);
96373c
     PR_vsnprintf(buffer, LOG_BUFFER, format, ap);
96373c
     va_end(ap);
96373c
@@ -1089,11 +1093,11 @@ task_export_thread(void *arg)
96373c
     slapi_pblock_get(pb, SLAPI_BACKEND_TASK, &task);
96373c
 
96373c
     g_incr_active_threadcnt();
96373c
-    for (count = 0, inp = instance_names; *inp; inp++, count++)
96373c
+    for (count = 0, inp = instance_names; inp && *inp; inp++, count++)
96373c
         ;
96373c
     slapi_task_begin(task, count);
96373c
 
96373c
-    for (inp = instance_names; *inp; inp++) {
96373c
+    for (inp = instance_names; inp && *inp; inp++) {
96373c
         int release_me = 0;
96373c
         /* lookup the backend */
96373c
         be = slapi_be_select_by_instance_name((const char *)*inp);
96373c
diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c
96373c
index 8477831..5bd318d 100644
96373c
--- a/ldap/servers/snmp/main.c
96373c
+++ b/ldap/servers/snmp/main.c
96373c
@@ -21,6 +21,7 @@
96373c
 #include "ldap.h"
96373c
 #include "ldif.h"
96373c
 #include <ctype.h>
96373c
+#include <errno.h>
96373c
 
96373c
 static char *agentx_master = NULL;
96373c
 static char *agent_logdir = NULL;
96373c
@@ -54,9 +55,17 @@ main(int argc, char *argv[])
96373c
     {
96373c
         char *s = getenv("DEBUG_SLEEP");
96373c
         if ((s != NULL) && isdigit(*s)) {
96373c
-            int secs = atoi(s);
96373c
+            char *endp = NULL;
96373c
+            long secs;
96373c
+            errno = 0;
96373c
+
96373c
             printf("%s pid is %d\n", argv[0], getpid());
96373c
-            sleep(secs);
96373c
+            secs = strtol(s, &endp, 10);
96373c
+            if (*endp != '\0' || errno == ERANGE) {
96373c
+                sleep(10);
96373c
+            } else {
96373c
+                sleep(secs);
96373c
+            }
96373c
         }
96373c
     }
96373c
 
96373c
-- 
96373c
2.9.5
96373c