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

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