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

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