zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

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

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