Blame SOURCES/0052-Ticket-49529-Fix-Coverity-warnings-invalid-deference.patch

058656
From 0b5cbcf45f3fb4b03a1f762c5704183787d30696 Mon Sep 17 00:00:00 2001
058656
From: Mark Reynolds <mreynolds@redhat.com>
058656
Date: Fri, 12 Jan 2018 08:38:22 -0500
058656
Subject: [PATCH] Ticket 49529 - Fix Coverity warnings: invalid deferences
058656
058656
Description:  So many of the warnings were false positives, but
058656
              I "fixed" 90% of them anyway for these two reasons:
058656
058656
              One, it's possible that a future change could actually
058656
              result in a NULL pointer being referenced.
058656
058656
              Two, it would be nice to stop these coverity warnings
058656
              so we can focus on real warnings.  Auto waivers also
058656
              don't always work as the surrounding code changes.
058656
058656
https://pagure.io/389-ds-base/issue/49529
058656
058656
Reviewed by: firstyear (Thanks!)
058656
058656
(cherry picked from commit 7e27face5ef021d883a44d70bb3e9732b115016f)
058656
---
058656
 ldap/servers/slapd/abandon.c      | 10 ++++++++--
058656
 ldap/servers/slapd/add.c          | 18 +++++++++++++++---
058656
 ldap/servers/slapd/bind.c         | 20 +++++++++++++++-----
058656
 ldap/servers/slapd/compare.c      | 17 +++++++++++++----
058656
 ldap/servers/slapd/connection.c   | 19 +++++++++++++------
058656
 ldap/servers/slapd/delete.c       |  4 ++--
058656
 ldap/servers/slapd/dn.c           |  7 +++++++
058656
 ldap/servers/slapd/entry.c        | 10 +++++++++-
058656
 ldap/servers/slapd/extendop.c     |  7 +++++++
058656
 ldap/servers/slapd/filter.c       |  6 +++++-
058656
 ldap/servers/slapd/modify.c       | 18 ++++++++++++++++--
058656
 ldap/servers/slapd/passwd_extop.c |  4 ++++
058656
 ldap/servers/slapd/psearch.c      | 13 +++++++++----
058656
 ldap/servers/slapd/result.c       | 14 +++++++++++++-
058656
 ldap/servers/slapd/search.c       |  5 ++++-
058656
 ldap/servers/slapd/task.c         |  5 +++++
058656
 16 files changed, 145 insertions(+), 32 deletions(-)
058656
058656
diff --git a/ldap/servers/slapd/abandon.c b/ldap/servers/slapd/abandon.c
058656
index 5c30c972d..e2237e5fc 100644
058656
--- a/ldap/servers/slapd/abandon.c
058656
+++ b/ldap/servers/slapd/abandon.c
058656
@@ -42,10 +42,16 @@ do_abandon(Slapi_PBlock *pb)
058656
     slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
 
058656
-    BerElement *ber = pb_op->o_ber;
058656
-
058656
     slapi_log_err(SLAPI_LOG_TRACE, "do_abandon", "->\n");
058656
 
058656
+    if (pb_op == NULL || pb_conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_abandon", "NULL param: pb_conn (0x%p) pb_op (0x%p)\n",
058656
+                      pb_conn, pb_op);
058656
+        return;
058656
+    }
058656
+
058656
+    BerElement *ber = pb_op->o_ber;
058656
+
058656
     /*
058656
      * Parse the abandon request.  It looks like this:
058656
      *
058656
diff --git a/ldap/servers/slapd/add.c b/ldap/servers/slapd/add.c
058656
index 0a4a5d7b2..8f2fdeac8 100644
058656
--- a/ldap/servers/slapd/add.c
058656
+++ b/ldap/servers/slapd/add.c
058656
@@ -66,6 +66,14 @@ do_add(Slapi_PBlock *pb)
058656
 
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
     slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
058656
+
058656
+
058656
+    if (operation == NULL || pb_conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_add", "NULL param: pb_conn (0x%p) pb_op (0x%p)\n",
058656
+                      pb_conn, operation);
058656
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, "param error", 0, NULL);
058656
+        return;
058656
+    }
058656
     ber = operation->o_ber;
058656
 
058656
     /* count the add request */
058656
@@ -450,8 +458,8 @@ op_shared_add(Slapi_PBlock *pb)
058656
 
058656
         if (!internal_op) {
058656
             slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d ADD dn=\"%s\"%s\n",
058656
-                             pb_conn->c_connid,
058656
-                             operation->o_opid,
058656
+                             pb_conn ? pb_conn->c_connid : -1,
058656
+                             operation ? operation->o_opid: -1,
058656
                              slapi_entry_get_dn_const(e),
058656
                              proxystr ? proxystr : "");
058656
         } else {
058656
@@ -865,7 +873,11 @@ handle_fast_add(Slapi_PBlock *pb, Slapi_Entry *entry)
058656
     int ret;
058656
 
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
-
058656
+    if (pb_conn == NULL){
058656
+        slapi_log_err(SLAPI_LOG_ERR, "handle_fast_add", "NULL param: pb_conn (0x%p)\n", pb_conn);
058656
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, "param error", 0, NULL);
058656
+        return;
058656
+    }
058656
     be = pb_conn->c_bi_backend;
058656
 
058656
     if ((be == NULL) || (be->be_wire_import == NULL)) {
058656
diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c
058656
index 4a8e4deaf..a34a21a77 100644
058656
--- a/ldap/servers/slapd/bind.c
058656
+++ b/ldap/servers/slapd/bind.c
058656
@@ -54,11 +54,7 @@ do_bind(Slapi_PBlock *pb)
058656
 {
058656
     Operation *pb_op = NULL;
058656
     Connection *pb_conn = NULL;
058656
-
058656
-    slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
-    slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
-
058656
-    BerElement *ber = pb_op->o_ber;
058656
+    BerElement *ber;
058656
     int err, isroot;
058656
     ber_tag_t method = LBER_DEFAULT;
058656
     ber_int_t version = -1;
058656
@@ -83,6 +79,16 @@ do_bind(Slapi_PBlock *pb)
058656
 
058656
     slapi_log_err(SLAPI_LOG_TRACE, "do_bind", "=>\n");
058656
 
058656
+    slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
+    slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
+    if (pb_op == NULL || pb_conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_bind", "NULL param: pb_conn (0x%p) pb_op (0x%p)\n",
058656
+                      pb_conn, pb_op);
058656
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, NULL, 0, NULL);
058656
+        goto free_and_return;
058656
+    }
058656
+    ber = pb_op->o_ber;
058656
+
058656
     /*
058656
      * Parse the bind request.  It looks like this:
058656
      *
058656
@@ -856,6 +862,10 @@ log_bind_access(
058656
     slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
 
058656
+    if (pb_op == NULL || pb_conn == NULL) {
058656
+        return;
058656
+    }
058656
+
058656
     if (method == LDAP_AUTH_SASL && saslmech && msg) {
058656
         slapi_log_access(LDAP_DEBUG_STATS,
058656
                          "conn=%" PRIu64 " op=%d BIND dn=\"%s\" "
058656
diff --git a/ldap/servers/slapd/compare.c b/ldap/servers/slapd/compare.c
058656
index 9bc6b693a..2626d91d0 100644
058656
--- a/ldap/servers/slapd/compare.c
058656
+++ b/ldap/servers/slapd/compare.c
058656
@@ -35,10 +35,7 @@ do_compare(Slapi_PBlock *pb)
058656
 {
058656
     Operation *pb_op = NULL;
058656
     Connection *pb_conn = NULL;
058656
-    slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
-    slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
-
058656
-    BerElement *ber = pb_op->o_ber;
058656
+    BerElement *ber;
058656
     char *rawdn = NULL;
058656
     const char *dn = NULL;
058656
     struct ava ava = {0};
058656
@@ -50,6 +47,18 @@ do_compare(Slapi_PBlock *pb)
058656
 
058656
     slapi_log_err(SLAPI_LOG_TRACE, "do_compare", "=>\n");
058656
 
058656
+    slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
+    slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
+
058656
+    if (pb_op == NULL || pb_conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_compare", "NULL param: pb_conn (0x%p) pb_op (0x%p)\n",
058656
+                      pb_conn, pb_op);
058656
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, NULL, 0, NULL);
058656
+        goto free_and_return;
058656
+    }
058656
+
058656
+    ber = pb_op->o_ber;
058656
+
058656
     /* count the compare request */
058656
     slapi_counter_increment(g_get_global_snmp_vars()->ops_tbl.dsCompareOps);
058656
 
058656
diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c
058656
index 8ef115691..fa24ec040 100644
058656
--- a/ldap/servers/slapd/connection.c
058656
+++ b/ldap/servers/slapd/connection.c
058656
@@ -1518,7 +1518,7 @@ connection_threadmain()
058656
         }
058656
 
058656
         if (!thread_turbo_flag && !more_data) {
058656
-	    Connection *pb_conn = NULL;
058656
+	        Connection *pb_conn = NULL;
058656
 
058656
             /* If more data is left from the previous connection_read_operation,
058656
                we should finish the op now.  Client might be thinking it's
058656
@@ -1530,6 +1530,13 @@ connection_threadmain()
058656
              * Connection wait for new work provides the conn and op for us.
058656
              */
058656
             slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
+            if (pb_conn == NULL) {
058656
+                slapi_log_err(SLAPI_LOG_ERR, "connection_threadmain",
058656
+                              "pb_conn is NULL\n");
058656
+                slapi_pblock_destroy(pb);
058656
+                g_decr_active_threadcnt();
058656
+                return;
058656
+            }
058656
 
058656
             switch (ret) {
058656
             case CONN_NOWORK:
058656
@@ -1702,11 +1709,11 @@ connection_threadmain()
058656
                  * so need locking from here on */
058656
                 signal_listner();
058656
                 /* with nunc-stans, I see an enormous amount of time spent in the poll() in
058656
- * connection_read_operation() when the below code is enabled - not sure why
058656
- * nunc-stans makes such a huge difference - for now, just disable this code
058656
- * when using nunc-stans - it is supposed to be an optimization but turns out
058656
- * to not be the opposite with nunc-stans
058656
- */
058656
+                 * connection_read_operation() when the below code is enabled - not sure why
058656
+                 * nunc-stans makes such a huge difference - for now, just disable this code
058656
+                 * when using nunc-stans - it is supposed to be an optimization but turns out
058656
+                 * to not be the opposite with nunc-stans
058656
+                 */
058656
             } else if (!enable_nunc_stans) { /* more data in conn - just put back on work_q - bypass poll */
058656
                 bypasspollcnt++;
058656
                 PR_EnterMonitor(conn->c_mutex);
058656
diff --git a/ldap/servers/slapd/delete.c b/ldap/servers/slapd/delete.c
058656
index ba238b18f..49cdab138 100644
058656
--- a/ldap/servers/slapd/delete.c
058656
+++ b/ldap/servers/slapd/delete.c
058656
@@ -262,8 +262,8 @@ op_shared_delete(Slapi_PBlock *pb)
058656
             slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
             slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
             slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d DEL dn=\"%s\"%s\n",
058656
-                             pb_conn->c_connid,
058656
-                             pb_op->o_opid,
058656
+                             pb_conn ? pb_conn->c_connid : -1,
058656
+                             pb_op ? pb_op->o_opid : -1,
058656
                              slapi_sdn_get_dn(sdn),
058656
                              proxystr ? proxystr : "");
058656
         } else {
058656
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
058656
index afca37214..abc155533 100644
058656
--- a/ldap/servers/slapd/dn.c
058656
+++ b/ldap/servers/slapd/dn.c
058656
@@ -2477,6 +2477,13 @@ slapi_sdn_copy(const Slapi_DN *from, Slapi_DN *to)
058656
 {
058656
     SDN_DUMP(from, "slapi_sdn_copy from");
058656
     SDN_DUMP(to, "slapi_sdn_copy to");
058656
+
058656
+    if (to == NULL || from == NULL){
058656
+        slapi_log_err(SLAPI_LOG_ERR, "slapi_sdn_copy",
058656
+                      "NULL param: from (0x%p) to (0x%p)\n", from, to);
058656
+        return;
058656
+    }
058656
+
058656
     slapi_sdn_done(to);
058656
     if (from->udn) {
058656
         to->flag = slapi_setbit_uchar(to->flag, FLAG_UDN);
058656
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
058656
index fbbc8faa0..32828b4e2 100644
058656
--- a/ldap/servers/slapd/entry.c
058656
+++ b/ldap/servers/slapd/entry.c
058656
@@ -1998,6 +1998,10 @@ slapi_entry_dup(const Slapi_Entry *e)
058656
     struct attrs_in_extension *aiep;
058656
 
058656
     PR_ASSERT(NULL != e);
058656
+    if (e == NULL){
058656
+        slapi_log_err(SLAPI_LOG_ERR, "slapi_entry_dup", "entry is NULL\n");
058656
+        return NULL;
058656
+    }
058656
 
058656
     ec = slapi_entry_alloc();
058656
 
058656
@@ -3660,7 +3664,11 @@ delete_values_sv_internal(
058656
     Slapi_Attr *a;
058656
     int retVal = LDAP_SUCCESS;
058656
 
058656
-/*
058656
+    if (e == NULL){
058656
+        slapi_log_err(SLAPI_LOG_ERR, "delete_values_sv_internal", "entry is NULL\n");
058656
+        return LDAP_OPERATIONS_ERROR;
058656
+    }
058656
+    /*
058656
      * If type is in the protected_attrs_all list, we could ignore the failure,
058656
      * as the attribute could only exist in the entry in the memory when the
058656
      * add/mod operation is done, while the retried entry from the db does not
058656
diff --git a/ldap/servers/slapd/extendop.c b/ldap/servers/slapd/extendop.c
058656
index 1594a8c9c..815949be6 100644
058656
--- a/ldap/servers/slapd/extendop.c
058656
+++ b/ldap/servers/slapd/extendop.c
058656
@@ -219,6 +219,13 @@ do_extended(Slapi_PBlock *pb)
058656
     slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
 
058656
+    if (pb_conn == NULL || pb_op == NULL) {
058656
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, "param error", 0, NULL);
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_extended",
058656
+                      "NULL param error: conn (0x%p) op (0x%p)\n", pb_conn, pb_op);
058656
+        goto free_and_return;
058656
+    }
058656
+
058656
     /*
058656
      * Parse the extended request. It looks like this:
058656
      *
058656
diff --git a/ldap/servers/slapd/filter.c b/ldap/servers/slapd/filter.c
058656
index fe3525f34..ef975e679 100644
058656
--- a/ldap/servers/slapd/filter.c
058656
+++ b/ldap/servers/slapd/filter.c
058656
@@ -292,7 +292,11 @@ get_filter_internal(Connection *conn, BerElement *ber, struct slapi_filter **fil
058656
 
058656
     case LDAP_FILTER_EXTENDED:
058656
         slapi_log_err(SLAPI_LOG_FILTER, "get_filter_internal", "EXTENDED\n");
058656
-        if (conn->c_ldapversion < 3) {
058656
+        if (conn == NULL) {
058656
+            slapi_log_err(SLAPI_LOG_ERR, "get_filter_internal",
058656
+                          "NULL param: conn (0x%p)\n", conn);
058656
+            err = LDAP_OPERATIONS_ERROR;
058656
+        } else if (conn->c_ldapversion < 3) {
058656
             slapi_log_err(SLAPI_LOG_ERR, "get_filter_internal",
058656
                           "Extensible filter received from v2 client\n");
058656
             err = LDAP_PROTOCOL_ERROR;
058656
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
058656
index 0dcac646b..10d263159 100644
058656
--- a/ldap/servers/slapd/modify.c
058656
+++ b/ldap/servers/slapd/modify.c
058656
@@ -122,9 +122,16 @@ do_modify(Slapi_PBlock *pb)
058656
     slapi_log_err(SLAPI_LOG_TRACE, "do_modify", "=>\n");
058656
 
058656
     slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
058656
-    ber = operation->o_ber;
058656
-
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
+    if (operation == NULL) {
058656
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR,
058656
+                         NULL, "operation is NULL parameter", 0, NULL);
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_modify",
058656
+            "NULL param:  pb_conn (0x%p) operation (0x%p)\n", pb_conn, operation);
058656
+        return;
058656
+    }
058656
+
058656
+    ber = operation->o_ber;
058656
 
058656
     /* count the modify request */
058656
     slapi_counter_increment(g_get_global_snmp_vars()->ops_tbl.dsModifyEntryOps);
058656
@@ -1165,6 +1172,13 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
058656
     internal_op = operation_is_flag_set(operation, OP_FLAG_INTERNAL);
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
 
058656
+    if (pb_conn == NULL || operation == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "op_shared_allow_pw_change",
058656
+                      "NULL param error: conn (0x%p) op (0x%p)\n", pb_conn, operation);
058656
+        rc = -1;
058656
+        goto done;
058656
+    }
058656
+
058656
     slapi_sdn_init_dn_byref(&sdn, dn);
058656
     pwpolicy = new_passwdPolicy(pb, (char *)slapi_sdn_get_ndn(&sdn));
058656
 
058656
diff --git a/ldap/servers/slapd/passwd_extop.c b/ldap/servers/slapd/passwd_extop.c
058656
index 54a9a6716..40145af2e 100644
058656
--- a/ldap/servers/slapd/passwd_extop.c
058656
+++ b/ldap/servers/slapd/passwd_extop.c
058656
@@ -486,6 +486,10 @@ passwd_modify_extop(Slapi_PBlock *pb)
058656
     /* Allow password modify only for SSL/TLS established connections and
058656
      * connections using SASL privacy layers */
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &conn;;
058656
+    if (conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "passwd_modify_extop", "conn is NULL");
058656
+        goto free_and_return;
058656
+    }
058656
     if (slapi_pblock_get(pb, SLAPI_CONN_SASL_SSF, &sasl_ssf) != 0) {
058656
         errMesg = "Could not get SASL SSF from connection\n";
058656
         rc = LDAP_OPERATIONS_ERROR;
058656
diff --git a/ldap/servers/slapd/psearch.c b/ldap/servers/slapd/psearch.c
058656
index e0dd2bf89..1bf062954 100644
058656
--- a/ldap/servers/slapd/psearch.c
058656
+++ b/ldap/servers/slapd/psearch.c
058656
@@ -271,6 +271,11 @@ ps_send_results(void *arg)
058656
     slapi_pblock_get(ps->ps_pblock, SLAPI_CONNECTION, &pb_conn);
058656
     slapi_pblock_get(ps->ps_pblock, SLAPI_OPERATION, &pb_op);
058656
 
058656
+    if (pb_conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "ps_send_results", "pb_conn is NULL\n");
058656
+        return;
058656
+    }
058656
+
058656
     /* need to acquire a reference to this connection so that it will not
058656
        be released or cleaned up out from under us */
058656
     PR_EnterMonitor(pb_conn->c_mutex);
058656
@@ -280,7 +285,7 @@ ps_send_results(void *arg)
058656
     if (conn_acq_flag) {
058656
         slapi_log_err(SLAPI_LOG_CONNS, "ps_send_results",
058656
                       "conn=%" PRIu64 " op=%d Could not acquire the connection - psearch aborted\n",
058656
-                      pb_conn->c_connid, pb_op->o_opid);
058656
+                      pb_conn->c_connid, pb_op ? pb_op->o_opid : -1);
058656
     }
058656
 
058656
     PR_Lock(psearch_list->pl_cvarlock);
058656
@@ -290,7 +295,7 @@ ps_send_results(void *arg)
058656
         if (pb_op == NULL || slapi_op_abandoned(ps->ps_pblock)) {
058656
             slapi_log_err(SLAPI_LOG_CONNS, "ps_send_results",
058656
                           "conn=%" PRIu64 " op=%d The operation has been abandoned\n",
058656
-                          pb_conn->c_connid, pb_op->o_opid);
058656
+                          pb_conn->c_connid, pb_op ? pb_op->o_opid : -1);
058656
             break;
058656
         }
058656
         if (NULL == ps->ps_eq_head) {
058656
@@ -532,7 +537,7 @@ ps_service_persistent_searches(Slapi_Entry *e, Slapi_Entry *eprev, ber_int_t chg
058656
         slapi_log_err(SLAPI_LOG_CONNS, "ps_service_persistent_searches",
058656
                       "conn=%" PRIu64 " op=%d entry %s with chgtype %d "
058656
                       "matches the ps changetype %d\n",
058656
-                      pb_conn->c_connid,
058656
+                      pb_conn ? pb_conn->c_connid : -1,
058656
                       pb_op->o_opid,
058656
                       edn, chgtype, ps->ps_changetypes);
058656
 
058656
@@ -609,7 +614,7 @@ ps_service_persistent_searches(Slapi_Entry *e, Slapi_Entry *eprev, ber_int_t chg
058656
         /* Turn 'em loose */
058656
         ps_wakeup_all();
058656
         slapi_log_err(SLAPI_LOG_TRACE, "ps_service_persistent_searches", "Enqueued entry "
058656
-                                                                         "\"%s\" on %d persistent search lists\n",
058656
+                      "\"%s\" on %d persistent search lists\n",
058656
                       slapi_entry_get_dn_const(e), matched);
058656
     } else {
058656
         slapi_log_err(SLAPI_LOG_TRACE, "ps_service_persistent_searches",
058656
diff --git a/ldap/servers/slapd/result.c b/ldap/servers/slapd/result.c
058656
index 2302ae96b..ce394d948 100644
058656
--- a/ldap/servers/slapd/result.c
058656
+++ b/ldap/servers/slapd/result.c
058656
@@ -396,7 +396,7 @@ send_ldap_result_ext(
058656
         break;
058656
 
058656
     case LDAP_REFERRAL:
058656
-        if (conn->c_ldapversion > LDAP_VERSION2) {
058656
+        if (conn && conn->c_ldapversion > LDAP_VERSION2) {
058656
             tag = LDAP_TAG_REFERRAL;
058656
             break;
058656
         }
058656
@@ -645,6 +645,11 @@ process_read_entry_controls(Slapi_PBlock *pb, char *oid)
058656
         BerElement *req_ber = NULL;
058656
         Operation *op = NULL;
058656
         slapi_pblock_get(pb, SLAPI_OPERATION, &op);
058656
+        if (op == NULL) {
058656
+            slapi_log_err(SLAPI_LOG_ERR, "process_read_entry_controls", "op is NULL\n");
058656
+            rc = -1;
058656
+            goto done;
058656
+        }
058656
 
058656
         if (strcmp(oid, LDAP_CONTROL_PRE_READ_ENTRY) == 0) {
058656
             /* first verify this is the correct operation for a pre-read entry control */
058656
@@ -2145,6 +2150,13 @@ encode_read_entry(Slapi_PBlock *pb, Slapi_Entry *e, char **attrs, int alluseratt
058656
     slapi_pblock_get(pb, SLAPI_OPERATION, &op);
058656
     slapi_pblock_get(pb, SLAPI_CONNECTION, &conn;;
058656
 
058656
+    if (conn == NULL || op == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "encode_read_entry",
058656
+                      "NULL param error: conn (0x%p) op (0x%p)\n", conn, op);
058656
+        rc = -1;
058656
+        goto cleanup;
058656
+    }
058656
+
058656
     /* Start the ber encoding with the DN */
058656
     rc = ber_printf(ber, "t{s{", LDAP_RES_SEARCH_ENTRY, slapi_entry_get_dn_const(e));
058656
     if (rc == -1) {
058656
diff --git a/ldap/servers/slapd/search.c b/ldap/servers/slapd/search.c
058656
index 5e3413245..731c6519e 100644
058656
--- a/ldap/servers/slapd/search.c
058656
+++ b/ldap/servers/slapd/search.c
058656
@@ -125,7 +125,10 @@ do_search(Slapi_PBlock *pb)
058656
         goto free_and_return;
058656
     }
058656
 
058656
-    slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
058656
+    if (slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn) != 0 || pb_conn == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "do_search", "pb_conn is NULL\n");
058656
+        goto free_and_return;
058656
+    }
058656
 
058656
     /*
058656
      * If nsslapd-minssf-exclude-rootdse is on, the minssf check has been
058656
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
058656
index 53a0af52d..002083c04 100644
058656
--- a/ldap/servers/slapd/task.c
058656
+++ b/ldap/servers/slapd/task.c
058656
@@ -199,6 +199,11 @@ slapi_task_log_status(Slapi_Task *task, char *format, ...)
058656
 {
058656
     va_list ap;
058656
 
058656
+    if (task == NULL) {
058656
+        slapi_log_err(SLAPI_LOG_ERR, "slapi_task_log_status",
058656
+                      "Slapi_Task is NULL, can not log status\n");
058656
+        return;
058656
+    }
058656
     if (!task->task_status)
058656
         task->task_status = (char *)slapi_ch_malloc(10 * LOG_BUFFER);
058656
     if (!task->task_status)
058656
-- 
058656
2.13.6
058656