andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0056-Ticket-49534-Fix-coverity-issues-and-regression.patch

96373c
From 961a1d68274453a9a0e79acdd4a3d6e3da146722 Mon Sep 17 00:00:00 2001
96373c
From: Mark Reynolds <mreynolds@redhat.com>
96373c
Date: Tue, 16 Jan 2018 10:14:34 -0500
96373c
Subject: [PATCH] Ticket 49534 - Fix coverity issues and regression
96373c
96373c
Description:  Fix regression introdcued in the previous coverity patch.
96373c
96373c
              Also fixed many other coverity issues.
96373c
96373c
https://pagure.io/389-ds-base/issue/49534
96373c
96373c
Reviewed by:  wibrown, tbordaz, lkrispen(Thanks!)
96373c
96373c
(cherry picked from commit 7658232cc427a5c46e94989eec9195f0392ee540)
96373c
---
96373c
 ldap/servers/plugins/acl/acl.c                     |  6 ++++
96373c
 ldap/servers/plugins/acl/acllas.c                  | 13 +++++--
96373c
 ldap/servers/plugins/automember/automember.c       |  6 ++++
96373c
 ldap/servers/plugins/cos/cos_cache.c               | 16 +++++++--
96373c
 ldap/servers/plugins/memberof/memberof_config.c    |  8 ++---
96373c
 ldap/servers/plugins/replication/cl5_clcache.c     |  9 +++--
96373c
 .../plugins/replication/repl5_replica_config.c     |  3 --
96373c
 ldap/servers/plugins/rootdn_access/rootdn_access.c |  7 +++-
96373c
 ldap/servers/plugins/uiduniq/7bit.c                | 18 +++++-----
96373c
 ldap/servers/plugins/views/views.c                 |  3 ++
96373c
 ldap/servers/slapd/auth.c                          |  3 +-
96373c
 ldap/servers/slapd/back-ldbm/dblayer.c             |  5 ++-
96373c
 ldap/servers/slapd/back-ldbm/filterindex.c         |  2 +-
96373c
 ldap/servers/slapd/back-ldbm/import-threads.c      | 10 +++---
96373c
 ldap/servers/slapd/back-ldbm/index.c               |  3 +-
96373c
 ldap/servers/slapd/back-ldbm/instance.c            |  4 +++
96373c
 ldap/servers/slapd/back-ldbm/ldbm_add.c            | 18 +++++++---
96373c
 .../slapd/back-ldbm/ldbm_attrcrypt_config.c        |  7 ++--
96373c
 .../servers/slapd/back-ldbm/ldbm_instance_config.c |  2 +-
96373c
 ldap/servers/slapd/back-ldbm/ldbm_search.c         |  4 +--
96373c
 ldap/servers/slapd/back-ldbm/vlv.c                 |  2 +-
96373c
 ldap/servers/slapd/back-ldbm/vlv_srch.c            |  2 +-
96373c
 ldap/servers/slapd/backend.c                       |  2 +-
96373c
 ldap/servers/slapd/compare.c                       |  7 ++--
96373c
 ldap/servers/slapd/connection.c                    | 40 ++++++++++++----------
96373c
 ldap/servers/slapd/control.c                       |  6 ++++
96373c
 ldap/servers/slapd/dse.c                           |  5 +--
96373c
 ldap/servers/slapd/eventq.c                        |  2 +-
96373c
 ldap/servers/slapd/extendop.c                      | 10 +++---
96373c
 ldap/servers/slapd/filter.c                        | 12 ++++---
96373c
 ldap/servers/slapd/index_subsystem.c               |  2 +-
96373c
 ldap/servers/slapd/main.c                          | 19 ++++++++--
96373c
 ldap/servers/slapd/mapping_tree.c                  |  2 +-
96373c
 ldap/servers/slapd/modify.c                        | 39 ++++++++++-----------
96373c
 ldap/servers/slapd/opshared.c                      |  7 ++++
96373c
 ldap/servers/slapd/passwd_extop.c                  |  4 +++
96373c
 ldap/servers/slapd/plugin.c                        |  8 +++--
96373c
 ldap/servers/slapd/plugin_internal_op.c            |  1 +
96373c
 ldap/servers/slapd/psearch.c                       |  6 ++--
96373c
 ldap/servers/slapd/pw.c                            |  3 +-
96373c
 ldap/servers/slapd/pw_mgmt.c                       | 30 ++++++++++------
96373c
 ldap/servers/slapd/result.c                        |  2 +-
96373c
 ldap/servers/slapd/saslbind.c                      |  5 +++
96373c
 ldap/servers/slapd/task.c                          |  5 +--
96373c
 ldap/servers/slapd/util.c                          | 12 ++++---
96373c
 ldap/servers/slapd/valueset.c                      | 10 ++++--
96373c
 ldap/servers/slapd/vattr.c                         | 20 ++++++++---
96373c
 ldap/servers/snmp/main.c                           | 19 ++++++----
96373c
 48 files changed, 276 insertions(+), 153 deletions(-)
96373c
96373c
diff --git a/ldap/servers/plugins/acl/acl.c b/ldap/servers/plugins/acl/acl.c
96373c
index f10c9f6b5..bc154c78f 100644
96373c
--- a/ldap/servers/plugins/acl/acl.c
96373c
+++ b/ldap/servers/plugins/acl/acl.c
96373c
@@ -437,6 +437,12 @@ acl_access_allowed(
96373c
      * pointers to them--we must always start afresh (see psearch.c).
96373c
     */
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &op);
96373c
+    if (op == NULL) {
96373c
+        slapi_log_err(SLAPI_LOG_ERR, plugin_name,
96373c
+                      "acl_access_allowed - NULL op\n");
96373c
+        ret_val = LDAP_OPERATIONS_ERROR;
96373c
+        goto cleanup_and_ret;
96373c
+    }
96373c
     if (operation_is_flag_set(op, OP_FLAG_PS) ||
96373c
         (aclpb->aclpb_curr_entry_sdn == NULL) ||
96373c
         (slapi_sdn_compare(aclpb->aclpb_curr_entry_sdn, e_sdn) != 0) ||
96373c
diff --git a/ldap/servers/plugins/acl/acllas.c b/ldap/servers/plugins/acl/acllas.c
96373c
index b9bea205c..3950fd405 100644
96373c
--- a/ldap/servers/plugins/acl/acllas.c
96373c
+++ b/ldap/servers/plugins/acl/acllas.c
96373c
@@ -4260,7 +4260,7 @@ acllas_replace_attr_macro(char *rule, lasInfo *lasinfo)
96373c
             /*
96373c
              * working_rule is the first member of working_list.
96373c
              * str points to the next $attr.attrName in working_rule.
96373c
-             * each member of working_list needs to have each occurence of
96373c
+             * each member of working_list needs to have each occurrence of
96373c
              * $attr.atrName replaced with the value of attrName in e.
96373c
              * If attrName is multi valued then this generates another
96373c
              * list which replaces the old one.
96373c
@@ -4273,8 +4273,7 @@ acllas_replace_attr_macro(char *rule, lasInfo *lasinfo)
96373c
             str = strstr(macro_str, ".");
96373c
             if (!str) {
96373c
                 slapi_log_err(SLAPI_LOG_ERR, plugin_name,
96373c
-                              "acllas_replace_attr_macro - Invalid macro \"%s\".",
96373c
-                              macro_str);
96373c
+                              "acllas_replace_attr_macro - Invalid macro \"%s\".", macro_str);
96373c
                 slapi_ch_free_string(&macro_str);
96373c
                 charray_free(working_list);
96373c
                 return NULL;
96373c
@@ -4282,10 +4281,18 @@ acllas_replace_attr_macro(char *rule, lasInfo *lasinfo)
96373c
 
96373c
             str++; /* skip the . */
96373c
             l = acl_strstr(&str[0], ")");
96373c
+            if (l == -1){
96373c
+                slapi_log_err(SLAPI_LOG_ERR, plugin_name,
96373c
+                              "acllas_replace_attr_macro - Invalid macro str \"%s\".", str);
96373c
+                slapi_ch_free_string(&macro_str);
96373c
+                charray_free(working_list);
96373c
+                return NULL;
96373c
+            }
96373c
             macro_attr_name = slapi_ch_malloc(l + 1);
96373c
             strncpy(macro_attr_name, &str[0], l);
96373c
             macro_attr_name[l] = '\0';
96373c
 
96373c
+
96373c
             slapi_entry_attr_find(e, macro_attr_name, &attr);
96373c
             if (NULL == attr) {
96373c
 
96373c
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
96373c
index 4c008e1f2..cbd25915a 100644
96373c
--- a/ldap/servers/plugins/automember/automember.c
96373c
+++ b/ldap/servers/plugins/automember/automember.c
96373c
@@ -1047,6 +1047,7 @@ automember_parse_regex_entry(struct configEntry *config, Slapi_Entry *e)
96373c
                         /* Order rules by target group DN */
96373c
                         if (slapi_sdn_compare(rule->target_group_dn, curr_rule->target_group_dn) < 0) {
96373c
                             PR_INSERT_BEFORE(&(rule->list), list);
96373c
+                            rule = NULL;
96373c
                             break;
96373c
                         }
96373c
 
96373c
@@ -1055,9 +1056,11 @@ automember_parse_regex_entry(struct configEntry *config, Slapi_Entry *e)
96373c
                         /* If we hit the end of the list, add to the tail. */
96373c
                         if ((PRCList *)config->inclusive_rules == list) {
96373c
                             PR_INSERT_BEFORE(&(rule->list), list);
96373c
+                            rule = NULL;
96373c
                             break;
96373c
                         }
96373c
                     }
96373c
+                    automember_free_regex_rule(rule);
96373c
                 } else {
96373c
                     /* Add to head of list */
96373c
                     PR_INSERT_LINK(&(rule->list), (PRCList *)config->inclusive_rules);
96373c
@@ -1101,6 +1104,7 @@ automember_parse_regex_entry(struct configEntry *config, Slapi_Entry *e)
96373c
                         /* Order rules by target group DN */
96373c
                         if (slapi_sdn_compare(rule->target_group_dn, curr_rule->target_group_dn) < 0) {
96373c
                             PR_INSERT_BEFORE(&(rule->list), list);
96373c
+                            rule = NULL;
96373c
                             break;
96373c
                         }
96373c
 
96373c
@@ -1109,6 +1113,7 @@ automember_parse_regex_entry(struct configEntry *config, Slapi_Entry *e)
96373c
                         /* If we hit the end of the list, add to the tail. */
96373c
                         if ((PRCList *)config->exclusive_rules == list) {
96373c
                             PR_INSERT_BEFORE(&(rule->list), list);
96373c
+                            rule = NULL;
96373c
                             break;
96373c
                         }
96373c
                     }
96373c
@@ -1116,6 +1121,7 @@ automember_parse_regex_entry(struct configEntry *config, Slapi_Entry *e)
96373c
                     /* Add to head of list */
96373c
                     PR_INSERT_LINK(&(rule->list), (PRCList *)config->exclusive_rules);
96373c
                 }
96373c
+                automember_free_regex_rule(rule);
96373c
             } else {
96373c
                 slapi_log_err(SLAPI_LOG_ERR, AUTOMEMBER_PLUGIN_SUBSYSTEM,
96373c
                               "automember_parse_regex_entry - Skipping invalid exclusive "
96373c
diff --git a/ldap/servers/plugins/cos/cos_cache.c b/ldap/servers/plugins/cos/cos_cache.c
96373c
index 3b3c05783..5e0cf1725 100644
96373c
--- a/ldap/servers/plugins/cos/cos_cache.c
96373c
+++ b/ldap/servers/plugins/cos/cos_cache.c
96373c
@@ -874,7 +874,7 @@ cos_dn_defs_cb(Slapi_Entry *e, void *callback_data)
96373c
 
96373c
     if (pCosAttribute && (!pCosTargetTree || !pCosTemplateDn)) {
96373c
         /* get the parent of the definition */
96373c
-        char *orig = slapi_dn_parent(pDn->val);
96373c
+        char *orig = pDn ? slapi_dn_parent(pDn->val) : NULL;
96373c
         char *parent = NULL;
96373c
         if (orig) {
96373c
             parent = slapi_create_dn_string("%s", orig);
96373c
@@ -900,7 +900,7 @@ cos_dn_defs_cb(Slapi_Entry *e, void *callback_data)
96373c
             slapi_log_err(SLAPI_LOG_ERR, COS_PLUGIN_SUBSYSTEM,
96373c
                           "cos_dn_defs_cb - "
96373c
                           "Failed to get parent dn of cos definition %s.\n",
96373c
-                          pDn->val);
96373c
+                          pDn ? pDn->val : "<NONE>");
96373c
             if (!pCosTemplateDn) {
96373c
                 if (!pCosTargetTree) {
96373c
                     slapi_log_err(SLAPI_LOG_ERR, COS_PLUGIN_SUBSYSTEM, "cos_dn_defs_cb - cosTargetTree and cosTemplateDn are not set.\n");
96373c
@@ -1843,6 +1843,13 @@ cos_cache_add_tmpl(cosTemplates **pTemplates, cosAttrValue *dn, cosAttrValue *ob
96373c
 
96373c
     slapi_log_err(SLAPI_LOG_TRACE, COS_PLUGIN_SUBSYSTEM, "--> cos_cache_add_tmpl\n");
96373c
 
96373c
+    if (dn == NULL) {
96373c
+        slapi_log_err(SLAPI_LOG_ERR, COS_PLUGIN_SUBSYSTEM,
96373c
+                      "cos_cache_add_tmpl - param cosAttrValue dn is NULL\n");
96373c
+        ret = -1;
96373c
+        goto done;
96373c
+    }
96373c
+
96373c
     /* create the attribute */
96373c
     theTemp = (cosTemplates *)slapi_ch_malloc(sizeof(cosTemplates));
96373c
     if (theTemp) {
96373c
@@ -1851,7 +1858,9 @@ cos_cache_add_tmpl(cosTemplates **pTemplates, cosAttrValue *dn, cosAttrValue *ob
96373c
         int index = 0;
96373c
         int template_default = 0;
96373c
         char *ptr = NULL;
96373c
-        char *normed = slapi_create_dn_string("%s", dn->val);
96373c
+        char *normed = NULL;
96373c
+
96373c
+        normed = slapi_create_dn_string("%s", dn->val);
96373c
         if (normed) {
96373c
             slapi_ch_free_string(&dn->val);
96373c
             dn->val = normed;
96373c
@@ -1964,6 +1973,7 @@ cos_cache_add_tmpl(cosTemplates **pTemplates, cosAttrValue *dn, cosAttrValue *ob
96373c
         ret = -1;
96373c
     }
96373c
 
96373c
+done:
96373c
     slapi_log_err(SLAPI_LOG_TRACE, COS_PLUGIN_SUBSYSTEM, "<-- cos_cache_add_tmpl\n");
96373c
     return ret;
96373c
 }
96373c
diff --git a/ldap/servers/plugins/memberof/memberof_config.c b/ldap/servers/plugins/memberof/memberof_config.c
96373c
index 3f22d95d6..8a27f5250 100644
96373c
--- a/ldap/servers/plugins/memberof/memberof_config.c
96373c
+++ b/ldap/servers/plugins/memberof/memberof_config.c
96373c
@@ -550,7 +550,7 @@ memberof_apply_config(Slapi_PBlock *pb __attribute__((unused)),
96373c
         }
96373c
 
96373c
         /* Build the new list */
96373c
-        for (i = 0; theConfig.groupattrs[i]; i++) {
96373c
+        for (i = 0; theConfig.groupattrs && theConfig.groupattrs[i]; i++) {
96373c
             theConfig.group_slapiattrs[i] = slapi_attr_new();
96373c
             slapi_attr_init(theConfig.group_slapiattrs[i], theConfig.groupattrs[i]);
96373c
         }
96373c
@@ -572,7 +572,7 @@ memberof_apply_config(Slapi_PBlock *pb __attribute__((unused)),
96373c
             bytes_out = snprintf(filter_str, filter_str_len - bytes_out, "(|");
96373c
 
96373c
             /* Add filter section for each groupattr. */
96373c
-            for (i = 0; theConfig.groupattrs[i]; i++) {
96373c
+            for (i = 0; theConfig.groupattrs && theConfig.groupattrs[i]; i++) {
96373c
                 bytes_out += snprintf(filter_str + bytes_out, filter_str_len - bytes_out, "(%s=*)", theConfig.groupattrs[i]);
96373c
             }
96373c
 
96373c
@@ -721,7 +721,7 @@ memberof_copy_config(MemberOfConfig *dest, MemberOfConfig *src)
96373c
             }
96373c
 
96373c
             /* Count how many values we have in the source list. */
96373c
-            for (j = 0; src->group_slapiattrs[j]; j++) {
96373c
+            for (j = 0; src->group_slapiattrs && src->group_slapiattrs[j]; j++) {
96373c
                 /* Do nothing. */
96373c
             }
96373c
 
96373c
@@ -731,7 +731,7 @@ memberof_copy_config(MemberOfConfig *dest, MemberOfConfig *src)
96373c
             }
96373c
 
96373c
             /* Copy the attributes. */
96373c
-            for (i = 0; src->group_slapiattrs[i]; i++) {
96373c
+            for (i = 0; src->group_slapiattrs && src->group_slapiattrs[i]; i++) {
96373c
                 dest->group_slapiattrs[i] = slapi_attr_dup(src->group_slapiattrs[i]);
96373c
             }
96373c
 
96373c
diff --git a/ldap/servers/plugins/replication/cl5_clcache.c b/ldap/servers/plugins/replication/cl5_clcache.c
96373c
index 40985b9a7..a8477a83a 100644
96373c
--- a/ldap/servers/plugins/replication/cl5_clcache.c
96373c
+++ b/ldap/servers/plugins/replication/cl5_clcache.c
96373c
@@ -676,7 +676,7 @@ clcache_initial_anchorcsn(CLC_Buffer *buf, int *flag)
96373c
         buf->buf_state = CLC_STATE_DONE;
96373c
     } else {
96373c
         csn_init_by_csn(buf->buf_current_csn, anchorcsn);
96373c
-        csn_as_string(buf->buf_current_csn, 0, (char *)buf->buf_key.data);
96373c
+        buf->buf_key.data = csn_as_string(buf->buf_current_csn, 0, (char *)buf->buf_key.data);
96373c
         slapi_log_err(SLAPI_LOG_REPL, "clcache_initial_anchorcsn",
96373c
                       "anchor is now: %s\n", (char *)buf->buf_key.data);
96373c
     }
96373c
@@ -746,10 +746,9 @@ clcache_adjust_anchorcsn(CLC_Buffer *buf, int *flag)
96373c
         buf->buf_state = CLC_STATE_DONE;
96373c
     } else {
96373c
         csn_init_by_csn(buf->buf_current_csn, anchorcsn);
96373c
-        csn_as_string(buf->buf_current_csn, 0, (char *)buf->buf_key.data);
96373c
-        slapi_log_err(SLAPI_LOG_REPL, buf->buf_agmt_name, "clcache_adjust_anchorcsn - "
96373c
-                                                          "anchor is now: %s\n",
96373c
-                      (char *)buf->buf_key.data);
96373c
+        buf->buf_key.data = csn_as_string(buf->buf_current_csn, 0, (char *)buf->buf_key.data);
96373c
+        slapi_log_err(SLAPI_LOG_REPL, buf->buf_agmt_name,
96373c
+                      "clcache_adjust_anchorcsn - anchor is now: %s\n", (char *)buf->buf_key.data);
96373c
     }
96373c
 
96373c
     return buf->buf_state;
96373c
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
96373c
index 95b933bb8..bda333362 100644
96373c
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
96373c
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
96373c
@@ -2527,9 +2527,6 @@ add_cleaned_rid(cleanruv_data *cleanruv_data, char *maxcsn)
96373c
     Replica *r;
96373c
     char *forcing;
96373c
 
96373c
-    if (data == NULL) {
96373c
-        return;
96373c
-    }
96373c
     rid = cleanruv_data->rid;
96373c
     r = cleanruv_data->replica;
96373c
     forcing = cleanruv_data->force;
96373c
diff --git a/ldap/servers/plugins/rootdn_access/rootdn_access.c b/ldap/servers/plugins/rootdn_access/rootdn_access.c
96373c
index b4db1202a..1cb999792 100644
96373c
--- a/ldap/servers/plugins/rootdn_access/rootdn_access.c
96373c
+++ b/ldap/servers/plugins/rootdn_access/rootdn_access.c
96373c
@@ -459,7 +459,7 @@ rootdn_check_access(Slapi_PBlock *pb)
96373c
     PRNetAddr *client_addr = NULL;
96373c
     PRHostEnt *host_entry = NULL;
96373c
     time_t curr_time;
96373c
-    struct tm *timeinfo;
96373c
+    struct tm *timeinfo = NULL;
96373c
     char *dnsName = NULL;
96373c
     int isRoot = 0;
96373c
     int rc = SLAPI_PLUGIN_SUCCESS;
96373c
@@ -478,6 +478,11 @@ rootdn_check_access(Slapi_PBlock *pb)
96373c
     if (open_time || daysAllowed) {
96373c
         curr_time = slapi_current_utc_time();
96373c
         timeinfo = localtime(&curr_time);
96373c
+        if (timeinfo == NULL) {
96373c
+            slapi_log_err(SLAPI_LOG_ERR, ROOTDN_PLUGIN_SUBSYSTEM,
96373c
+                "rootdn_check_access - Failed to get localtime\n");
96373c
+            return -1;
96373c
+        }
96373c
     }
96373c
     /*
96373c
      *  First check TOD restrictions, continue through if we are in the open "window"
96373c
diff --git a/ldap/servers/plugins/uiduniq/7bit.c b/ldap/servers/plugins/uiduniq/7bit.c
96373c
index b23e652cf..60fcbab93 100644
96373c
--- a/ldap/servers/plugins/uiduniq/7bit.c
96373c
+++ b/ldap/servers/plugins/uiduniq/7bit.c
96373c
@@ -715,18 +715,18 @@ preop_modrdn(Slapi_PBlock *pb)
96373c
 int
96373c
 NS7bitAttr_Init(Slapi_PBlock *pb)
96373c
 {
96373c
-    int err = 0;
96373c
+    int32_t err = 0;
96373c
     Slapi_Entry *plugin_entry = NULL;
96373c
     char *plugin_type = NULL;
96373c
-    int preadd = SLAPI_PLUGIN_PRE_ADD_FN;
96373c
-    int premod = SLAPI_PLUGIN_PRE_MODIFY_FN;
96373c
-    int premdn = SLAPI_PLUGIN_PRE_MODRDN_FN;
96373c
+    int32_t preadd = SLAPI_PLUGIN_PRE_ADD_FN;
96373c
+    int32_t premod = SLAPI_PLUGIN_PRE_MODIFY_FN;
96373c
+    int32_t premdn = SLAPI_PLUGIN_PRE_MODRDN_FN;
96373c
 
96373c
     BEGIN
96373c
-    int attr_count = 0;
96373c
-    int argc;
96373c
-    char **argv;
96373c
-    int valid_suffix = 0;
96373c
+    int32_t attr_count = 0;
96373c
+    int32_t argc = 0;
96373c
+    char **argv = NULL;
96373c
+    int32_t valid_suffix = 0;
96373c
 
96373c
     /* Declare plugin version */
96373c
     err = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
96373c
@@ -752,7 +752,7 @@ NS7bitAttr_Init(Slapi_PBlock *pb)
96373c
         break;
96373c
 
96373c
     err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
96373c
-    if (err)
96373c
+    if (err || argv == NULL)
96373c
         break;
96373c
 
96373c
     for (attr_count = 0; argv && argv[attr_count]; attr_count++) {
96373c
diff --git a/ldap/servers/plugins/views/views.c b/ldap/servers/plugins/views/views.c
96373c
index 6ba3e290d..6f784f599 100644
96373c
--- a/ldap/servers/plugins/views/views.c
96373c
+++ b/ldap/servers/plugins/views/views.c
96373c
@@ -558,6 +558,9 @@ views_cache_index(void)
96373c
         /* copy over the views */
96373c
         for (i = 0; i < theCache.view_count; i++) {
96373c
             theCache.ppViewIndex[i] = theView;
96373c
+            if (theView == NULL){
96373c
+                break;
96373c
+            }
96373c
             theView = theView->list.pNext;
96373c
         }
96373c
 
96373c
diff --git a/ldap/servers/slapd/auth.c b/ldap/servers/slapd/auth.c
96373c
index b8e171b27..a2050b990 100644
96373c
--- a/ldap/servers/slapd/auth.c
96373c
+++ b/ldap/servers/slapd/auth.c
96373c
@@ -463,7 +463,8 @@ handle_handshake_done(PRFileDesc *prfd, void *clientData)
96373c
             slapi_log_access(LDAP_DEBUG_STATS,
96373c
                              "conn=%" PRIu64 " %s %i-bit %s; client %s; issuer %s\n",
96373c
                              conn->c_connid,
96373c
-                             sslversion, keySize, cipher ? cipher : "NULL",
96373c
+                             sslversion, keySize,
96373c
+                             cipher ? cipher : "NULL",
96373c
                              subject ? escape_string(subject, sbuf) : "NULL",
96373c
                              issuer ? escape_string(issuer, ibuf) : "NULL");
96373c
             if (issuer)
96373c
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
96373c
index 9e557a24a..5d870e364 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
96373c
@@ -3007,7 +3007,7 @@ dblayer_erase_index_file_ex(backend *be, struct attrinfo *a, PRBool use_lock, in
96373c
     struct dblayer_private_env *pEnv = NULL;
96373c
     ldbm_instance *inst = NULL;
96373c
     dblayer_handle *handle = NULL;
96373c
-    char dbName[MAXPATHLEN];
96373c
+    char dbName[MAXPATHLEN] = {0};
96373c
     char *dbNamep;
96373c
     char *p;
96373c
     int dbbasenamelen, dbnamelen;
96373c
@@ -3098,8 +3098,7 @@ dblayer_erase_index_file_ex(backend *be, struct attrinfo *a, PRBool use_lock, in
96373c
                     dbNamep = (char *)slapi_ch_realloc(dbNamep, dbnamelen);
96373c
                 }
96373c
                 p = dbNamep + dbbasenamelen;
96373c
-                sprintf(p, "%c%s%s",
96373c
-                        get_sep(dbNamep), a->ai_type, LDBM_FILENAME_SUFFIX);
96373c
+                sprintf(p, "%c%s%s", get_sep(dbNamep), a->ai_type, LDBM_FILENAME_SUFFIX);
96373c
                 rc = dblayer_db_remove_ex(pEnv, dbNamep, 0, 0);
96373c
                 a->ai_dblayer = NULL;
96373c
                 if (dbNamep != dbName)
96373c
diff --git a/ldap/servers/slapd/back-ldbm/filterindex.c b/ldap/servers/slapd/back-ldbm/filterindex.c
96373c
index fd079077c..e8c3c2008 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/filterindex.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/filterindex.c
96373c
@@ -563,7 +563,7 @@ range_candidates(
96373c
 
96373c
     /* Check if it is for bulk import. */
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &op);
96373c
-    if (entryrdn_get_switch() && operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
96373c
+    if (entryrdn_get_switch() && op && operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
96373c
         operation_is_flag_set(op, OP_FLAG_BULK_IMPORT)) {
96373c
         /* parentid is treated specially that is needed for the bulk import. (See #48755) */
96373c
         operator= SLAPI_OP_RANGE_NO_IDL_SORT | SLAPI_OP_RANGE_NO_ALLIDS;
96373c
diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c
96373c
index b8cd9aaa0..0419865c9 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/import-threads.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/import-threads.c
96373c
@@ -1664,8 +1664,7 @@ upgradedn_producer(void *param)
96373c
                 slapi_ch_free_string(&rdn;;
96373c
             }
96373c
         } else {
96373c
-            e =
96373c
-                slapi_str2entry(data.data, SLAPI_STR2ENTRY_USE_OBSOLETE_DNFORMAT);
96373c
+            e = slapi_str2entry(data.data, SLAPI_STR2ENTRY_USE_OBSOLETE_DNFORMAT);
96373c
             rdn = slapi_ch_strdup(slapi_entry_get_rdn_const(e));
96373c
             if (NULL == rdn) {
96373c
                 Slapi_RDN srdn;
96373c
@@ -1683,6 +1682,7 @@ upgradedn_producer(void *param)
96373c
             slapi_log_err(SLAPI_LOG_WARNING, "upgradedn_producer",
96373c
                           "%s: Skipping badly formatted entry (id %lu)\n",
96373c
                           inst->inst_name, (u_long)temp_id);
96373c
+            slapi_ch_free_string(&rdn;;
96373c
             continue;
96373c
         }
96373c
 
96373c
@@ -2183,6 +2183,7 @@ done:
96373c
     free_IDarray(&dn_norm_sp_conflicts);
96373c
     slapi_ch_free_string(&ecopy);
96373c
     slapi_ch_free(&(data.data));
96373c
+    slapi_ch_free_string(&rdn;;
96373c
     if (job->upgradefd) {
96373c
         fclose(job->upgradefd);
96373c
     }
96373c
@@ -3783,7 +3784,7 @@ out:
96373c
     slapi_ch_free_string(&search_scope);
96373c
 
96373c
 
96373c
-    if (fd > 0) {
96373c
+    if (fd >= 0) {
96373c
         close(fd);
96373c
     }
96373c
 
96373c
@@ -3949,8 +3950,7 @@ import_get_and_add_parent_rdns(ImportWorkerInfo *info,
96373c
         rc = slapi_rdn_add_srdn_to_all_rdns(srdn, &mysrdn);
96373c
         if (rc) {
96373c
             slapi_log_err(SLAPI_LOG_ERR, "import_get_and_add_parent_rdns",
96373c
-                          "Failed to merge Slapi_RDN %s to RDN\n",
96373c
-                          slapi_sdn_get_dn(bdn->dn_sdn));
96373c
+                          "Failed to merge Slapi_RDN to RDN\n");
96373c
         }
96373c
     bail:
96373c
         slapi_ch_free(&data.data);
96373c
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
96373c
index 587f4d991..7e1cdd0db 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/index.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/index.c
96373c
@@ -749,7 +749,7 @@ index_add_mods(
96373c
                                           mods[i]->mod_type,
96373c
                                           &curr_attr);
96373c
                     if (curr_attr) {
96373c
-                        for (j = 0; mods_valueArray[j] != NULL; j++) {
96373c
+                        for (j = 0; mods_valueArray && mods_valueArray[j] != NULL; j++) {
96373c
                             if (!slapi_valueset_find(curr_attr, all_vals, mods_valueArray[j])) {
96373c
                                 /*
96373c
                                  * If the mod del value is not found in all_vals
96373c
@@ -1054,6 +1054,7 @@ index_read_ext_allids(
96373c
     for (retry_count = 0; retry_count < IDL_FETCH_RETRY_COUNT; retry_count++) {
96373c
         *err = NEW_IDL_DEFAULT;
96373c
         PRIntervalTime interval;
96373c
+        idl_free(&idl);
96373c
         idl = idl_fetch_ext(be, db, &key, db_txn, ai, err, allidslimit);
96373c
         if (*err == DB_LOCK_DEADLOCK) {
96373c
             ldbm_nasty("index_read_ext_allids", "index read retrying transaction", 1045, *err);
96373c
diff --git a/ldap/servers/slapd/back-ldbm/instance.c b/ldap/servers/slapd/back-ldbm/instance.c
96373c
index d4715ab9c..7f9f423a5 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/instance.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/instance.c
96373c
@@ -352,6 +352,10 @@ ldbm_instance_find_by_name(struct ldbminfo *li, char *name)
96373c
     Object *inst_obj;
96373c
     ldbm_instance *inst;
96373c
 
96373c
+    if (name == NULL) {
96373c
+        return NULL;
96373c
+    }
96373c
+
96373c
     inst_obj = objset_first_obj(li->li_instance_set);
96373c
     while (inst_obj != NULL) {
96373c
         inst = (ldbm_instance *)object_get_data(inst_obj);
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
96373c
index f29945a7e..c93d44a65 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
96373c
@@ -60,7 +60,7 @@ ldbm_back_add(Slapi_PBlock *pb)
96373c
     ID pid;
96373c
     int isroot;
96373c
     char *errbuf = NULL;
96373c
-    back_txn txn;
96373c
+    back_txn txn = {0};
96373c
     back_txnid parent_txn;
96373c
     int retval = -1;
96373c
     char *msg;
96373c
@@ -96,6 +96,7 @@ ldbm_back_add(Slapi_PBlock *pb)
96373c
     PRUint64 conn_id;
96373c
     int op_id;
96373c
     int result_sent = 0;
96373c
+
96373c
     if (slapi_pblock_get(pb, SLAPI_CONN_ID, &conn_id) < 0) {
96373c
         conn_id = 0; /* connection is NULL */
96373c
     }
96373c
@@ -109,6 +110,11 @@ ldbm_back_add(Slapi_PBlock *pb)
96373c
     slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
96373c
     slapi_pblock_get(pb, SLAPI_BACKEND, &be);
96373c
 
96373c
+    if (operation == NULL) {
96373c
+        slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_add", "NULL operation\n");
96373c
+        return LDAP_OPERATIONS_ERROR;
96373c
+    }
96373c
+
96373c
     is_resurect_operation = operation_is_flag_set(operation, OP_FLAG_RESURECT_ENTRY);
96373c
     is_tombstone_operation = operation_is_flag_set(operation, OP_FLAG_TOMBSTONE_ENTRY);
96373c
     is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
96373c
@@ -126,6 +132,11 @@ ldbm_back_add(Slapi_PBlock *pb)
96373c
         goto error_return;
96373c
     }
96373c
 
96373c
+    if (e == NULL){
96373c
+        slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_add", "entry is NULL.\n");
96373c
+        goto error_return;
96373c
+    }
96373c
+
96373c
     /* sdn & parentsdn need to be initialized before "goto *_return" */
96373c
     slapi_sdn_init(&parentsdn);
96373c
 
96373c
@@ -169,9 +180,8 @@ ldbm_back_add(Slapi_PBlock *pb)
96373c
      * before we make our last abandon check to avoid race conditions in
96373c
      * the code that processes abandon operations.
96373c
      */
96373c
-    if (operation) {
96373c
-        operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
96373c
-    }
96373c
+    operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
96373c
+
96373c
     if (slapi_op_abandoned(pb)) {
96373c
         ldap_result_code = -1; /* needs to distinguish from "success" */
96373c
         goto error_return;
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c b/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c
96373c
index e792c26cf..9ecb09903 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c
96373c
@@ -124,8 +124,8 @@ ldbm_instance_attrcrypt_config_add_callback(Slapi_PBlock *pb __attribute__((unus
96373c
 {
96373c
     ldbm_instance *inst = (ldbm_instance *)arg;
96373c
     char *attribute_name = NULL;
96373c
-    int cipher = 0;
96373c
-    int ret = 0;
96373c
+    int32_t cipher = 0;
96373c
+    int32_t ret = SLAPI_DSE_CALLBACK_OK;
96373c
 
96373c
     returntext[0] = '\0';
96373c
 
96373c
@@ -146,7 +146,6 @@ ldbm_instance_attrcrypt_config_add_callback(Slapi_PBlock *pb __attribute__((unus
96373c
             *returncode = LDAP_UNWILLING_TO_PERFORM;
96373c
             ret = SLAPI_DSE_CALLBACK_ERROR;
96373c
         } else {
96373c
-
96373c
             ainfo_get(inst->inst_be, attribute_name, &ai;;
96373c
             /* If we couldn't find a non-default attrinfo, then that means
96373c
              * that no indexing or encryption has yet been defined for this attribute
96373c
@@ -172,9 +171,7 @@ ldbm_instance_attrcrypt_config_add_callback(Slapi_PBlock *pb __attribute__((unus
96373c
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
96373c
                 ret = SLAPI_DSE_CALLBACK_ERROR;
96373c
             }
96373c
-            ret = SLAPI_DSE_CALLBACK_OK;
96373c
         }
96373c
-
96373c
     } else {
96373c
         ret = SLAPI_DSE_CALLBACK_ERROR;
96373c
     }
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c b/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c
96373c
index c2e49d5ab..eb2603897 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c
96373c
@@ -1307,7 +1307,7 @@ ldbm_instance_delete_instance_entry_callback(Slapi_PBlock *pb __attribute__((unu
96373c
                                              char *returntext,
96373c
                                              void *arg)
96373c
 {
96373c
-    char *instance_name;
96373c
+    char *instance_name = NULL;
96373c
     struct ldbminfo *li = (struct ldbminfo *)arg;
96373c
     struct ldbm_instance *inst = NULL;
96373c
 
96373c
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
96373c
index 02a21bf92..8f3111813 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
96373c
@@ -1157,7 +1157,7 @@ subtree_candidates(
96373c
     slapi_pblock_get(pb, SLAPI_REQUESTOR_ISROOT, &isroot);
96373c
     /* Check if it is for bulk import. */
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &op);
96373c
-    if (entryrdn_get_switch() && operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
96373c
+    if (op && entryrdn_get_switch() && operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
96373c
         operation_is_flag_set(op, OP_FLAG_BULK_IMPORT)) {
96373c
         is_bulk_import = PR_TRUE;
96373c
     }
96373c
@@ -1168,7 +1168,7 @@ subtree_candidates(
96373c
      * since tombstone entries are not indexed in the ancestorid index.
96373c
      * Note: they are indexed in the entryrdn index.
96373c
      */
96373c
-    if (candidates != NULL && (idl_length(candidates) > FILTER_TEST_THRESHOLD)) {
96373c
+    if (candidates != NULL && (idl_length(candidates) > FILTER_TEST_THRESHOLD) && e) {
96373c
         IDList *tmp = candidates, *descendants = NULL;
96373c
         back_txn txn = {NULL};
96373c
 
96373c
diff --git a/ldap/servers/slapd/back-ldbm/vlv.c b/ldap/servers/slapd/back-ldbm/vlv.c
96373c
index 9a1a1c63e..23825c2d5 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/vlv.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/vlv.c
96373c
@@ -1518,7 +1518,7 @@ vlv_trim_candidates_byvalue(backend *be, const IDList *candidates, const sort_sp
96373c
 {
96373c
     PRUint32 si = 0; /* The Selected Index */
96373c
     PRUint32 low = 0;
96373c
-    PRUint32 high = candidates->b_nids - 1;
96373c
+    PRUint32 high = 0;
96373c
     PRUint32 current = 0;
96373c
     ID id = NOID;
96373c
     int found = 0;
96373c
diff --git a/ldap/servers/slapd/back-ldbm/vlv_srch.c b/ldap/servers/slapd/back-ldbm/vlv_srch.c
96373c
index e9780b590..c4c0875ad 100644
96373c
--- a/ldap/servers/slapd/back-ldbm/vlv_srch.c
96373c
+++ b/ldap/servers/slapd/back-ldbm/vlv_srch.c
96373c
@@ -168,7 +168,7 @@ vlvSearch_init(struct vlvSearch *p, Slapi_PBlock *pb, const Slapi_Entry *e, ldbm
96373c
 
96373c
             /* switch context back to the DSE backend */
96373c
             slapi_pblock_set(pb, SLAPI_BACKEND, oldbe);
96373c
-            slapi_pblock_set(pb, SLAPI_PLUGIN, oldbe->be_database);
96373c
+            slapi_pblock_set(pb, SLAPI_PLUGIN, oldbe ? oldbe->be_database: NULL);
96373c
         }
96373c
 
96373c
         /* make (&(parentid=idofbase)(|(originalfilter)(objectclass=referral))) */
96373c
diff --git a/ldap/servers/slapd/backend.c b/ldap/servers/slapd/backend.c
96373c
index fb3eb77a3..78c00a5a8 100644
96373c
--- a/ldap/servers/slapd/backend.c
96373c
+++ b/ldap/servers/slapd/backend.c
96373c
@@ -171,7 +171,7 @@ slapi_be_issuffix(const Slapi_Backend *be, const Slapi_DN *suffix)
96373c
     struct suffixlist *list;
96373c
     int r = 0;
96373c
     /* this backend is no longer valid */
96373c
-    if (be->be_state != BE_STATE_DELETED) {
96373c
+    if (be && be->be_state != BE_STATE_DELETED) {
96373c
         int i = 0, count;
96373c
 
96373c
         count = slapi_counter_get_value(be->be_suffixcounter);
96373c
diff --git a/ldap/servers/slapd/compare.c b/ldap/servers/slapd/compare.c
96373c
index 2626d91d0..88a6c3599 100644
96373c
--- a/ldap/servers/slapd/compare.c
96373c
+++ b/ldap/servers/slapd/compare.c
96373c
@@ -47,9 +47,11 @@ do_compare(Slapi_PBlock *pb)
96373c
 
96373c
     slapi_log_err(SLAPI_LOG_TRACE, "do_compare", "=>\n");
96373c
 
96373c
+    /* have to init this here so we can "done" it below if we short circuit */
96373c
+    slapi_sdn_init(&sdn;;
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
@@ -62,9 +64,6 @@ do_compare(Slapi_PBlock *pb)
96373c
     /* count the compare request */
96373c
     slapi_counter_increment(g_get_global_snmp_vars()->ops_tbl.dsCompareOps);
96373c
 
96373c
-    /* have to init this here so we can "done" it below if we short circuit */
96373c
-    slapi_sdn_init(&sdn;;
96373c
-
96373c
     /*
96373c
      * Parse the compare request.  It looks like this:
96373c
      *
96373c
diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c
96373c
index fa24ec040..5d2b64ed2 100644
96373c
--- a/ldap/servers/slapd/connection.c
96373c
+++ b/ldap/servers/slapd/connection.c
96373c
@@ -1526,18 +1526,6 @@ connection_threadmain()
96373c
                [blackflag 624234] */
96373c
             ret = connection_wait_for_new_work(pb, interval);
96373c
 
96373c
-            /*
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
                 PR_ASSERT(interval != PR_INTERVAL_NO_TIMEOUT); /* this should never happen with PR_INTERVAL_NO_TIMEOUT */
96373c
@@ -1550,15 +1538,22 @@ connection_threadmain()
96373c
                 return;
96373c
             case CONN_FOUND_WORK_TO_DO:
96373c
                 /* note - don't need to lock here - connection should only
96373c
-                       be used by this thread - since c_gettingber is set to 1
96373c
-                       in connection_activity when the conn is added to the
96373c
-                       work queue, setup_pr_read_pds won't add the connection prfd
96373c
-                       to the poll list */
96373c
+                   be used by this thread - since c_gettingber is set to 1
96373c
+                   in connection_activity when the conn is added to the
96373c
+                   work queue, setup_pr_read_pds won't add the connection prfd
96373c
+                   to the poll list */
96373c
+                slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
+                if (pb_conn == NULL) {
96373c
+                    slapi_log_err(SLAPI_LOG_ERR, "connection_threadmain", "pb_conn is NULL\n");
96373c
+                    slapi_pblock_destroy(pb);
96373c
+                    g_decr_active_threadcnt();
96373c
+                    return;
96373c
+                }
96373c
                 if (pb_conn->c_opscompleted == 0) {
96373c
                     /*
96373c
-                         * We have a new connection, set the anonymous reslimit idletimeout
96373c
-                         * if applicable.
96373c
-                         */
96373c
+                     * We have a new connection, set the anonymous reslimit idletimeout
96373c
+                     * if applicable.
96373c
+                     */
96373c
                     char *anon_dn = config_get_anon_limits_dn();
96373c
                     int idletimeout;
96373c
                     /* If an anonymous limits dn is set, use it to set the limits. */
96373c
@@ -1578,6 +1573,7 @@ connection_threadmain()
96373c
                     slapi_log_err(SLAPI_LOG_ERR, "connection_threadmain",
96373c
                                   "Could not add/remove IO layers from connection\n");
96373c
                 }
96373c
+                break;
96373c
             default:
96373c
                 break;
96373c
             }
96373c
@@ -1604,6 +1600,12 @@ connection_threadmain()
96373c
         /* Once we're here we have a pb */
96373c
         slapi_pblock_get(pb, SLAPI_CONNECTION, &conn;;
96373c
         slapi_pblock_get(pb, SLAPI_OPERATION, &op);
96373c
+        if (conn == NULL || op == NULL) {
96373c
+            slapi_log_err(SLAPI_LOG_ERR, "connection_threadmain", "NULL param: conn (0x%p) op (0x%p)\n", conn, op);
96373c
+            slapi_pblock_destroy(pb);
96373c
+            g_decr_active_threadcnt();
96373c
+            return;
96373c
+        }
96373c
         maxthreads = config_get_maxthreadsperconn();
96373c
         more_data = 0;
96373c
         ret = connection_read_operation(conn, op, &tag, &more_data);
96373c
diff --git a/ldap/servers/slapd/control.c b/ldap/servers/slapd/control.c
96373c
index 366ec7897..4fd8473be 100644
96373c
--- a/ldap/servers/slapd/control.c
96373c
+++ b/ldap/servers/slapd/control.c
96373c
@@ -304,6 +304,12 @@ get_ldapmessage_controls_ext(
96373c
 
96373c
             Operation *pb_op = NULL;
96373c
             slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
96373c
+            if (pb_op == NULL) {
96373c
+                rc = LDAP_OPERATIONS_ERROR;
96373c
+                slapi_log_err(SLAPI_LOG_ERR, "get_ldapmessage_controls_ext", "NULL pb_op\n");
96373c
+                slapi_rwlock_unlock(supported_controls_lock);
96373c
+                goto free_and_return;
96373c
+            }
96373c
 
96373c
             if (supported_controls == NULL ||
96373c
                 supported_controls[i] == NULL ||
96373c
diff --git a/ldap/servers/slapd/dse.c b/ldap/servers/slapd/dse.c
96373c
index 662e91aa7..932912c17 100644
96373c
--- a/ldap/servers/slapd/dse.c
96373c
+++ b/ldap/servers/slapd/dse.c
96373c
@@ -1727,8 +1727,9 @@ dse_modify(Slapi_PBlock *pb) /* JCM There should only be one exit point from thi
96373c
     }
96373c
 
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
96373c
-    internal_op = operation_is_flag_set(pb_op, OP_FLAG_INTERNAL);
96373c
-
96373c
+    if (pb_op){
96373c
+        internal_op = operation_is_flag_set(pb_op, OP_FLAG_INTERNAL);
96373c
+    }
96373c
     /* Find the entry we are about to modify. */
96373c
     ec = dse_get_entry_copy(pdse, sdn, DSE_USE_LOCK);
96373c
     if (ec == NULL) {
96373c
diff --git a/ldap/servers/slapd/eventq.c b/ldap/servers/slapd/eventq.c
96373c
index 8fccf38a8..a491acd0a 100644
96373c
--- a/ldap/servers/slapd/eventq.c
96373c
+++ b/ldap/servers/slapd/eventq.c
96373c
@@ -462,7 +462,7 @@ slapi_eq_get_arg(Slapi_Eq_Context ctx)
96373c
     slapi_eq_context **p;
96373c
 
96373c
     PR_ASSERT(eq_initialized);
96373c
-    if (!eq_stopped) {
96373c
+    if (eq && !eq_stopped) {
96373c
         PR_Lock(eq->eq_lock);
96373c
         p = &(eq->eq_queue);
96373c
         while (p && *p != NULL) {
96373c
diff --git a/ldap/servers/slapd/extendop.c b/ldap/servers/slapd/extendop.c
96373c
index 815949be6..98595bcaa 100644
96373c
--- a/ldap/servers/slapd/extendop.c
96373c
+++ b/ldap/servers/slapd/extendop.c
96373c
@@ -135,10 +135,12 @@ extop_handle_import_start(Slapi_PBlock *pb, char *extoid __attribute__((unused))
96373c
      * connection block & mark this connection as belonging to a bulk import
96373c
      */
96373c
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
-    PR_EnterMonitor(pb_conn->c_mutex);
96373c
-    pb_conn->c_flags |= CONN_FLAG_IMPORT;
96373c
-    pb_conn->c_bi_backend = be;
96373c
-    PR_ExitMonitor(pb_conn->c_mutex);
96373c
+    if (pb_conn) {
96373c
+        PR_EnterMonitor(pb_conn->c_mutex);
96373c
+        pb_conn->c_flags |= CONN_FLAG_IMPORT;
96373c
+        pb_conn->c_bi_backend = be;
96373c
+        PR_ExitMonitor(pb_conn->c_mutex);
96373c
+    }
96373c
 
96373c
     slapi_pblock_set(pb, SLAPI_EXT_OP_RET_OID, EXTOP_BULK_IMPORT_START_OID);
96373c
     bv.bv_val = NULL;
96373c
diff --git a/ldap/servers/slapd/filter.c b/ldap/servers/slapd/filter.c
96373c
index ef975e679..2ac3d2cd8 100644
96373c
--- a/ldap/servers/slapd/filter.c
96373c
+++ b/ldap/servers/slapd/filter.c
96373c
@@ -686,11 +686,13 @@ slapi_filter_dup(Slapi_Filter *f)
96373c
         outl = &out->f_list;
96373c
         for (fl = f->f_list; fl != NULL; fl = fl->f_next) {
96373c
             (*outl) = slapi_filter_dup(fl);
96373c
-            (*outl)->f_next = 0;
96373c
-            if (lastout)
96373c
-                lastout->f_next = *outl;
96373c
-            lastout = *outl;
96373c
-            outl = &((*outl)->f_next);
96373c
+            if (*outl){
96373c
+                (*outl)->f_next = 0;
96373c
+                if (lastout)
96373c
+                    lastout->f_next = *outl;
96373c
+                lastout = *outl;
96373c
+                outl = &((*outl)->f_next);
96373c
+            }
96373c
         }
96373c
         break;
96373c
 
96373c
diff --git a/ldap/servers/slapd/index_subsystem.c b/ldap/servers/slapd/index_subsystem.c
96373c
index 47ca90047..97cb7b489 100644
96373c
--- a/ldap/servers/slapd/index_subsystem.c
96373c
+++ b/ldap/servers/slapd/index_subsystem.c
96373c
@@ -1179,7 +1179,7 @@ index_subsys_assign_decoder(Slapi_Filter *f)
96373c
                          * have the same associated attributes configuration for now
96373c
                          * though they may have different namespaces
96373c
                          */
96373c
-                        if (index_subsys_index_matches_index(f->assigned_decoder, index)) {
96373c
+                        if (index_subsys_index_matches_index(f->assigned_decoder, index) && last) {
96373c
                             /* add to end */
96373c
                             last->list.pNext = index_subsys_index_shallow_dup(index);
96373c
                             last = last->list.pNext;
96373c
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
96373c
index ddaceffea..e1493bb80 100644
96373c
--- a/ldap/servers/slapd/main.c
96373c
+++ b/ldap/servers/slapd/main.c
96373c
@@ -683,13 +683,26 @@ main(int argc, char **argv)
96373c
     {
96373c
         char *s = getenv("DEBUG_SLEEP");
96373c
         if ((s != NULL) && isdigit(*s)) {
96373c
-            int secs = atoi(s);
96373c
-            printf("slapd pid is %d\n", getpid());
96373c
+            char *endp = NULL;
96373c
+            int64_t secs;
96373c
+            errno = 0;
96373c
+
96373c
+            secs = strtol(s, &endp, 10);
96373c
+            if ( endp == s ||
96373c
+                 *endp != '\0' ||
96373c
+                 ((secs == LONG_MIN || secs == LONG_MAX) && errno == ERANGE) ||
96373c
+                 secs < 1 )
96373c
+            {
96373c
+                /* Invalid value, default to 30 seconds */
96373c
+                secs = 30;
96373c
+            } else if (secs > 3600) {
96373c
+                secs = 3600;
96373c
+            }
96373c
+            printf("slapd pid is %d - sleeping for %ld\n", getpid(), secs);
96373c
             sleep(secs);
96373c
         }
96373c
     }
96373c
 
96373c
-
96373c
     /* used to set configfile to the default config file name here */
96373c
     if ((mcfg.myname = strrchr(argv[0], '/')) == NULL) {
96373c
         mcfg.myname = slapi_ch_strdup(argv[0]);
96373c
diff --git a/ldap/servers/slapd/mapping_tree.c b/ldap/servers/slapd/mapping_tree.c
96373c
index 8cc531834..472a2f6aa 100644
96373c
--- a/ldap/servers/slapd/mapping_tree.c
96373c
+++ b/ldap/servers/slapd/mapping_tree.c
96373c
@@ -2629,7 +2629,7 @@ mtn_get_be(mapping_tree_node *target_node, Slapi_PBlock *pb, Slapi_Backend **be,
96373c
                     (target_node->mtn_be_states[*index] == SLAPI_BE_STATE_OFFLINE)) {
96373c
                     slapi_log_err(SLAPI_LOG_TRACE, "mtn_get_be",
96373c
                                   "Operation attempted on backend in OFFLINE state : %s\n",
96373c
-                                  target_node->mtn_backend_names[*index]);
96373c
+                                  target_node->mtn_backend_names ? target_node->mtn_backend_names[*index] : "Unknown backend");
96373c
                     result = LDAP_OPERATIONS_ERROR;
96373c
                     *be = defbackend_get_backend();
96373c
                 }
96373c
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
96373c
index 10d263159..f2f6d1783 100644
96373c
--- a/ldap/servers/slapd/modify.c
96373c
+++ b/ldap/servers/slapd/modify.c
96373c
@@ -123,7 +123,7 @@ do_modify(Slapi_PBlock *pb)
96373c
 
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
96373c
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
-    if (operation == NULL) {
96373c
+    if (operation == NULL || pb_conn == 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
@@ -1156,6 +1156,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
     char *proxydn = NULL;
96373c
     char *proxystr = NULL;
96373c
     char *errtext = NULL;
96373c
+    int32_t needpw = 0;
96373c
 
96373c
     slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op);
96373c
     if (repl_op) {
96373c
@@ -1169,24 +1170,23 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
     slapi_pblock_get(pb, SLAPI_REQUESTOR_ISROOT, &isroot);
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
96373c
     slapi_pblock_get(pb, SLAPI_PWPOLICY, &pwresponse_req);
96373c
-    internal_op = operation_is_flag_set(operation, OP_FLAG_INTERNAL);
96373c
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
+    slapi_sdn_init_dn_byref(&sdn, dn);
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
+    if (operation == NULL) {
96373c
+        slapi_log_err(SLAPI_LOG_ERR, "op_shared_allow_pw_change", "NULL operation\n");
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
+    if (pb_conn) {
96373c
+        needpw = pb_conn->c_needpw;
96373c
+    }
96373c
 
96373c
     /* get the proxy auth dn if the proxy auth control is present */
96373c
     if ((proxy_err = proxyauth_get_dn(pb, &proxydn, &errtext)) != LDAP_SUCCESS) {
96373c
         if (operation_is_flag_set(operation, OP_FLAG_ACTION_LOG_ACCESS)) {
96373c
             slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d MOD dn=\"%s\"\n",
96373c
-                             pb_conn->c_connid, operation->o_opid,
96373c
+                             pb_conn ? pb_conn->c_connid: -1, operation->o_opid,
96373c
                              slapi_sdn_get_dn(&sdn));
96373c
         }
96373c
 
96373c
@@ -1195,6 +1195,9 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
         goto done;
96373c
     }
96373c
 
96373c
+    pwpolicy = new_passwdPolicy(pb, (char *)slapi_sdn_get_ndn(&sdn));
96373c
+    internal_op = operation_is_flag_set(operation, OP_FLAG_INTERNAL);
96373c
+
96373c
     /* internal operation has root permissions for subtrees it is allowed to access */
96373c
     if (!internal_op) {
96373c
         /* slapi_acl_check_mods needs an array of LDAPMods, but
96373c
@@ -1225,7 +1228,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
                     proxystr = slapi_ch_smprintf(" authzid=\"%s\"", proxydn);
96373c
                 }
96373c
                 slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d MOD dn=\"%s\"%s\n",
96373c
-                                 pb_conn->c_connid, operation->o_opid,
96373c
+                                 pb_conn ? pb_conn->c_connid : -1, operation->o_opid,
96373c
                                  slapi_sdn_get_dn(&sdn), proxystr ? proxystr : "");
96373c
             }
96373c
 
96373c
@@ -1254,7 +1257,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
 
96373c
         /* Check if password policy allows users to change their passwords.*/
96373c
         if (!operation->o_isroot && slapi_sdn_compare(&sdn, &operation->o_sdn) == 0 &&
96373c
-            !pb_conn->c_needpw && !pwpolicy->pw_change) {
96373c
+            !needpw && !pwpolicy->pw_change) {
96373c
             if (pwresponse_req == 1) {
96373c
                 slapi_pwpolicy_make_response_control(pb, -1, -1, LDAP_PWPOLICY_PWDMODNOTALLOWED);
96373c
             }
96373c
@@ -1267,7 +1270,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
                 }
96373c
 
96373c
                 slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d MOD dn=\"%s\"%s, %s\n",
96373c
-                                 pb_conn->c_connid, operation->o_opid,
96373c
+                                 pb_conn ? pb_conn->c_connid : -1, operation->o_opid,
96373c
                                  slapi_sdn_get_dn(&sdn),
96373c
                                  proxystr ? proxystr : "",
96373c
                                  "user is not allowed to change password");
96373c
@@ -1280,8 +1283,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
 
96373c
     /* check if password is within password minimum age;
96373c
        error result is sent directly from check_pw_minage */
96373c
-    if (pb_conn && !pb_conn->c_needpw &&
96373c
-        check_pw_minage(pb, &sdn, mod->mod_bvalues) == 1) {
96373c
+    if (!needpw && check_pw_minage(pb, &sdn, mod->mod_bvalues) == 1) {
96373c
         if (operation_is_flag_set(operation, OP_FLAG_ACTION_LOG_ACCESS)) {
96373c
             if (proxydn) {
96373c
                 proxystr = slapi_ch_smprintf(" authzid=\"%s\"", proxydn);
96373c
@@ -1289,7 +1291,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
 
96373c
             if (!internal_op) {
96373c
                 slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d MOD dn=\"%s\"%s, %s\n",
96373c
-                                 pb_conn->c_connid,
96373c
+                                 pb_conn ? pb_conn->c_connid : -1,
96373c
                                  operation->o_opid,
96373c
                                  slapi_sdn_get_dn(&sdn),
96373c
                                  proxystr ? proxystr : "",
96373c
@@ -1303,17 +1305,14 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
                                  "within password minimum age");
96373c
             }
96373c
         }
96373c
-
96373c
         rc = -1;
96373c
         goto done;
96373c
     }
96373c
 
96373c
-
96373c
     /* check password syntax; remember the old password;
96373c
        error sent directly from check_pw_syntax function */
96373c
     valuearray_init_bervalarray(mod->mod_bvalues, &values);
96373c
-    switch (check_pw_syntax_ext(pb, &sdn, values, old_pw, NULL,
96373c
-                                mod->mod_op, smods)) {
96373c
+    switch (check_pw_syntax_ext(pb, &sdn, values, old_pw, NULL, mod->mod_op, smods)) {
96373c
     case 0: /* success */
96373c
         rc = 1;
96373c
         break;
96373c
@@ -1326,7 +1325,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
96373c
 
96373c
             if (!internal_op) {
96373c
                 slapi_log_access(LDAP_DEBUG_STATS, "conn=%" PRIu64 " op=%d MOD dn=\"%s\"%s, %s\n",
96373c
-                                 pb_conn->c_connid,
96373c
+                                 pb_conn ? pb_conn->c_connid : -1,
96373c
                                  operation->o_opid,
96373c
                                  slapi_sdn_get_dn(&sdn),
96373c
                                  proxystr ? proxystr : "",
96373c
diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c
96373c
index 46dcf6fba..50b7ae8f6 100644
96373c
--- a/ldap/servers/slapd/opshared.c
96373c
+++ b/ldap/servers/slapd/opshared.c
96373c
@@ -276,6 +276,13 @@ op_shared_search(Slapi_PBlock *pb, int send_result)
96373c
     slapi_pblock_get(pb, SLAPI_SEARCH_STRFILTER, &fstr);
96373c
     slapi_pblock_get(pb, SLAPI_SEARCH_ATTRS, &attrs);
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
96373c
+    if (operation == NULL) {
96373c
+        op_shared_log_error_access(pb, "SRCH", base, "NULL operation");
96373c
+        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, "NULL operation", 0, NULL);
96373c
+        rc = -1;
96373c
+        goto free_and_return_nolock;
96373c
+    }
96373c
+
96373c
     internal_op = operation_is_flag_set(operation, OP_FLAG_INTERNAL);
96373c
     flag_psearch = operation_is_flag_set(operation, OP_FLAG_PS);
96373c
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
diff --git a/ldap/servers/slapd/passwd_extop.c b/ldap/servers/slapd/passwd_extop.c
96373c
index 40145af2e..5f21f2f71 100644
96373c
--- a/ldap/servers/slapd/passwd_extop.c
96373c
+++ b/ldap/servers/slapd/passwd_extop.c
96373c
@@ -727,6 +727,10 @@ parse_req_done:
96373c
       */
96373c
     Operation *pb_op = NULL;
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
96373c
+    if (pb_op == NULL) {
96373c
+        slapi_log_err(SLAPI_LOG_ERR, "passwd_modify_extop", "pb_op is NULL");
96373c
+        goto free_and_return;
96373c
+    }
96373c
 
96373c
     operation_set_target_spec(pb_op, slapi_entry_get_sdn(targetEntry));
96373c
     slapi_pblock_set(pb, SLAPI_REQUESTOR_ISROOT, &pb_op->o_isroot);
96373c
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
96373c
index e02133abc..2db3c7fcd 100644
96373c
--- a/ldap/servers/slapd/plugin.c
96373c
+++ b/ldap/servers/slapd/plugin.c
96373c
@@ -3625,9 +3625,11 @@ plugin_invoke_plugin_pb(struct slapdplugin *plugin, int operation, Slapi_PBlock
96373c
         return PR_TRUE;
96373c
 
96373c
     slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
96373c
-
96373c
-
96373c
-    PR_ASSERT(pb_op);
96373c
+    if (pb_op == NULL) {
96373c
+        slapi_log_err(SLAPI_LOG_ERR, "plugin_invoke_plugin_pb", "pb_op is NULL");
96373c
+        PR_ASSERT(0);
96373c
+        return PR_FALSE;
96373c
+    }
96373c
 
96373c
     target_spec = operation_get_target_spec(pb_op);
96373c
 
96373c
diff --git a/ldap/servers/slapd/plugin_internal_op.c b/ldap/servers/slapd/plugin_internal_op.c
96373c
index 52b8df8c3..f6bbafb92 100644
96373c
--- a/ldap/servers/slapd/plugin_internal_op.c
96373c
+++ b/ldap/servers/slapd/plugin_internal_op.c
96373c
@@ -527,6 +527,7 @@ internal_plugin_search_entry_callback(Slapi_Entry *e, void *callback_data)
96373c
     this_entry = (Entry_Node *)slapi_ch_calloc(1, sizeof(Entry_Node));
96373c
 
96373c
     if ((this_entry->data = slapi_entry_dup(e)) == NULL) {
96373c
+        slapi_ch_free((void**)&this_entry);
96373c
         return (0);
96373c
     }
96373c
 
96373c
diff --git a/ldap/servers/slapd/psearch.c b/ldap/servers/slapd/psearch.c
96373c
index 1bf062954..8ad268a85 100644
96373c
--- a/ldap/servers/slapd/psearch.c
96373c
+++ b/ldap/servers/slapd/psearch.c
96373c
@@ -353,8 +353,8 @@ ps_send_results(void *arg)
96373c
                 if (rc) {
96373c
                     slapi_log_err(SLAPI_LOG_CONNS, "ps_send_results",
96373c
                                   "conn=%" PRIu64 " op=%d Error %d sending entry %s with op status %d\n",
96373c
-                                  pb_conn->c_connid, pb_op->o_opid,
96373c
-                                  rc, slapi_entry_get_dn_const(ec), pb_op->o_status);
96373c
+                                  pb_conn->c_connid, pb_op ? pb_op->o_opid: -1,
96373c
+                                  rc, slapi_entry_get_dn_const(ec), pb_op ? pb_op->o_status : -1);
96373c
                 }
96373c
             }
96373c
 
96373c
@@ -401,7 +401,7 @@ ps_send_results(void *arg)
96373c
 
96373c
     slapi_log_err(SLAPI_LOG_CONNS, "ps_send_results",
96373c
                   "conn=%" PRIu64 " op=%d Releasing the connection and operation\n",
96373c
-                  conn->c_connid, pb_op->o_opid);
96373c
+                  conn->c_connid, pb_op ? pb_op->o_opid : -1);
96373c
     /* Delete this op from the connection's list */
96373c
     connection_remove_operation_ext(ps->ps_pblock, conn, pb_op);
96373c
 
96373c
diff --git a/ldap/servers/slapd/pw.c b/ldap/servers/slapd/pw.c
96373c
index 0cf795b41..53464c64a 100644
96373c
--- a/ldap/servers/slapd/pw.c
96373c
+++ b/ldap/servers/slapd/pw.c
96373c
@@ -1741,7 +1741,6 @@ new_passwdPolicy(Slapi_PBlock *pb, const char *dn)
96373c
             pwdpolicy->pw_min8bit = SLAPD_DEFAULT_PW_MIN8BIT;
96373c
             pwdpolicy->pw_maxrepeats = SLAPD_DEFAULT_PW_MAXREPEATS;
96373c
             pwdpolicy->pw_mincategories = SLAPD_DEFAULT_PW_MINCATEGORIES;
96373c
-            pwdpolicy->pw_mintokenlength = SLAPD_DEFAULT_PW_MINTOKENLENGTH;
96373c
             pwdpolicy->pw_maxage = SLAPD_DEFAULT_PW_MAXAGE;
96373c
             pwdpolicy->pw_minage = SLAPD_DEFAULT_PW_MINAGE;
96373c
             pwdpolicy->pw_warning = SLAPD_DEFAULT_PW_WARNING;
96373c
@@ -2229,7 +2228,7 @@ slapi_check_account_lock(Slapi_PBlock *pb, Slapi_Entry *bind_target_entry, int p
96373c
     /*
96373c
      * Check if the password policy has to be checked or not
96373c
      */
96373c
-    if (!check_password_policy || pwpolicy->pw_lockout == 0) {
96373c
+    if (!check_password_policy || !pwpolicy || pwpolicy->pw_lockout == 0) {
96373c
         goto notlocked;
96373c
     }
96373c
 
96373c
diff --git a/ldap/servers/slapd/pw_mgmt.c b/ldap/servers/slapd/pw_mgmt.c
96373c
index 50bcbde99..602868470 100644
96373c
--- a/ldap/servers/slapd/pw_mgmt.c
96373c
+++ b/ldap/servers/slapd/pw_mgmt.c
96373c
@@ -44,6 +44,7 @@ need_new_pw(Slapi_PBlock *pb, Slapi_Entry *e, int pwresponse_req)
96373c
     char graceUserTime[16] = {0};
96373c
     Connection *pb_conn = NULL;
96373c
     long t;
96373c
+    int needpw = 0;
96373c
 
96373c
     if (NULL == e) {
96373c
         return (-1);
96373c
@@ -91,6 +92,9 @@ need_new_pw(Slapi_PBlock *pb, Slapi_Entry *e, int pwresponse_req)
96373c
     slapi_ch_free_string(&passwordExpirationTime);
96373c
 
96373c
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
+    if (pb_conn) {
96373c
+        needpw = pb_conn->c_needpw;
96373c
+    }
96373c
 
96373c
     /* Check if password has been reset */
96373c
     if (pw_exp_date == NO_TIME) {
96373c
@@ -99,7 +103,11 @@ need_new_pw(Slapi_PBlock *pb, Slapi_Entry *e, int pwresponse_req)
96373c
         if (pwpolicy->pw_must_change) {
96373c
             /* set c_needpw for this connection to be true.  this client
96373c
                now can only change its own password */
96373c
-            pb_conn->c_needpw = 1;
96373c
+            if (pb_conn){
96373c
+                pb_conn->c_needpw = needpw = 1;
96373c
+            } else {
96373c
+                needpw = 1;
96373c
+            }
96373c
             t = 0;
96373c
             /* We need to include "changeafterreset" error in
96373c
              * passwordpolicy response control. So, we will not be
96373c
@@ -121,7 +129,7 @@ skip:
96373c
     /* if password never expires, don't need to go on; return 0 */
96373c
     if (pwpolicy->pw_exp == 0) {
96373c
         /* check for "changeafterreset" condition */
96373c
-        if (pb_conn->c_needpw == 1) {
96373c
+        if (needpw == 1) {
96373c
             if (pwresponse_req) {
96373c
                 slapi_pwpolicy_make_response_control(pb, -1, -1, LDAP_PWPOLICY_CHGAFTERRESET);
96373c
             }
96373c
@@ -150,7 +158,7 @@ skip:
96373c
             slapi_mods_done(&smods);
96373c
             if (pwresponse_req) {
96373c
                 /* check for "changeafterreset" condition */
96373c
-                if (pb_conn->c_needpw == 1) {
96373c
+                if (needpw == 1) {
96373c
                     slapi_pwpolicy_make_response_control(pb, -1,
96373c
                                                          ((pwpolicy->pw_gracelimit) - pwdGraceUserTime),
96373c
                                                          LDAP_PWPOLICY_CHGAFTERRESET);
96373c
@@ -182,9 +190,11 @@ skip:
96373c
         if (pb_conn && (LDAP_VERSION2 == pb_conn->c_ldapversion)) {
96373c
             Operation *pb_op = NULL;
96373c
             slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
96373c
-            /* We close the connection only with LDAPv2 connections */
96373c
-            disconnect_server(pb_conn, pb_op->o_connid,
96373c
-                              pb_op->o_opid, SLAPD_DISCONNECT_UNBIND, 0);
96373c
+            if (pb_op) {
96373c
+                /* We close the connection only with LDAPv2 connections */
96373c
+                disconnect_server(pb_conn, pb_op->o_connid,
96373c
+                                  pb_op->o_opid, SLAPD_DISCONNECT_UNBIND, 0);
96373c
+            }
96373c
         }
96373c
         /* Apply current modifications */
96373c
         pw_apply_mods(sdn, &smods);
96373c
@@ -207,7 +217,7 @@ skip:
96373c
             /* reset the expiration time to current + warning time
96373c
              * and set passwordExpWarned to true
96373c
              */
96373c
-            if (pb_conn->c_needpw != 1) {
96373c
+            if (needpw != 1) {
96373c
                 pw_exp_date = time_plus_sec(cur_time, pwpolicy->pw_warning);
96373c
             }
96373c
 
96373c
@@ -227,14 +237,14 @@ skip:
96373c
         slapi_mods_done(&smods);
96373c
         if (pwresponse_req) {
96373c
             /* check for "changeafterreset" condition */
96373c
-            if (pb_conn->c_needpw == 1) {
96373c
+            if (needpw == 1) {
96373c
                 slapi_pwpolicy_make_response_control(pb, t, -1, LDAP_PWPOLICY_CHGAFTERRESET);
96373c
             } else {
96373c
                 slapi_pwpolicy_make_response_control(pb, t, -1, -1);
96373c
             }
96373c
         }
96373c
 
96373c
-        if (pb_conn->c_needpw == 1) {
96373c
+        if (needpw == 1) {
96373c
             slapi_add_pwd_control(pb, LDAP_CONTROL_PWEXPIRED, 0);
96373c
         } else {
96373c
             slapi_add_pwd_control(pb, LDAP_CONTROL_PWEXPIRING, t);
96373c
@@ -250,7 +260,7 @@ skip:
96373c
     pw_apply_mods(sdn, &smods);
96373c
     slapi_mods_done(&smods);
96373c
     /* Leftover from "changeafterreset" condition */
96373c
-    if (pb_conn->c_needpw == 1) {
96373c
+    if (needpw == 1) {
96373c
         slapi_add_pwd_control(pb, LDAP_CONTROL_PWEXPIRED, 0);
96373c
     }
96373c
     /* passes checking, return 0 */
96373c
diff --git a/ldap/servers/slapd/result.c b/ldap/servers/slapd/result.c
96373c
index ce394d948..6892ccfdc 100644
96373c
--- a/ldap/servers/slapd/result.c
96373c
+++ b/ldap/servers/slapd/result.c
96373c
@@ -1340,7 +1340,7 @@ send_specific_attrs(Slapi_Entry *e, char **attrs, Slapi_Operation *op, Slapi_PBl
96373c
         attrs = attrs_ext;
96373c
     }
96373c
 
96373c
-    for (i = 0; attrs && attrs[i] != NULL; i++) {
96373c
+    for (i = 0; my_searchattrs && attrs && attrs[i] != NULL; i++) {
96373c
         char *current_type_name = attrs[i];
96373c
         Slapi_ValueSet **values = NULL;
96373c
         int attr_free_flags = 0;
96373c
diff --git a/ldap/servers/slapd/saslbind.c b/ldap/servers/slapd/saslbind.c
96373c
index 67da97148..0907c623f 100644
96373c
--- a/ldap/servers/slapd/saslbind.c
96373c
+++ b/ldap/servers/slapd/saslbind.c
96373c
@@ -884,6 +884,11 @@ ids_sasl_check_bind(Slapi_PBlock *pb)
96373c
     slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
     PR_ASSERT(pb_conn);
96373c
 
96373c
+    if (pb_conn == NULL){
96373c
+        slapi_log_err(SLAPI_LOG_ERR, "ids_sasl_check_bind", "pb_conn is NULL\n");
96373c
+        return;
96373c
+    }
96373c
+
96373c
     PR_EnterMonitor(pb_conn->c_mutex); /* BIG LOCK */
96373c
     continuing = pb_conn->c_flags & CONN_FLAG_SASL_CONTINUE;
96373c
     pb_conn->c_flags &= ~CONN_FLAG_SASL_CONTINUE; /* reset flag */
96373c
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
96373c
index 002083c04..4bd8895ff 100644
96373c
--- a/ldap/servers/slapd/task.c
96373c
+++ b/ldap/servers/slapd/task.c
96373c
@@ -2335,8 +2335,9 @@ task_fixup_tombstone_thread(void *arg)
96373c
     Slapi_Task *task = task_data->task;
96373c
     char **base = task_data->base;
96373c
     char *filter = NULL;
96373c
-    int fixup_count = 0;
96373c
-    int rc, i, j;
96373c
+    int32_t fixup_count = 0;
96373c
+    int32_t rc = 0;
96373c
+    int32_t i, j;
96373c
 
96373c
     if (!task) {
96373c
         return; /* no task */
96373c
diff --git a/ldap/servers/slapd/util.c b/ldap/servers/slapd/util.c
96373c
index a0f3268da..a72de9b07 100644
96373c
--- a/ldap/servers/slapd/util.c
96373c
+++ b/ldap/servers/slapd/util.c
96373c
@@ -746,8 +746,9 @@ normalize_mods2bvals(const LDAPMod **mods)
96373c
             struct berval **mbvp = NULL;
96373c
 
96373c
             for (mbvp = mods[w]->mod_bvalues,
96373c
-                normmbvp = normalized_mods[w]->mod_bvalues;
96373c
-                 mbvp && *mbvp; mbvp++, normmbvp++) {
96373c
+                 normmbvp = normalized_mods[w]->mod_bvalues;
96373c
+                 normmbvp && mbvp && *mbvp; mbvp++, normmbvp++)
96373c
+            {
96373c
                 if (is_dn_syntax) {
96373c
                     Slapi_DN *sdn = slapi_sdn_new_dn_byref((*mbvp)->bv_val);
96373c
                     if (slapi_sdn_get_dn(sdn)) {
96373c
@@ -769,8 +770,9 @@ normalize_mods2bvals(const LDAPMod **mods)
96373c
             char **mvp = NULL;
96373c
 
96373c
             for (mvp = mods[w]->mod_values,
96373c
-                normmbvp = normalized_mods[w]->mod_bvalues;
96373c
-                 mvp && *mvp; mvp++, normmbvp++) {
96373c
+                 normmbvp = normalized_mods[w]->mod_bvalues;
96373c
+                 normmbvp && mvp && *mvp; mvp++, normmbvp++)
96373c
+            {
96373c
                 vlen = strlen(*mvp);
96373c
 
96373c
                 *normmbvp =
96373c
@@ -801,7 +803,7 @@ normalize_mods2bvals(const LDAPMod **mods)
96373c
         PR_ASSERT(normmbvp - normalized_mods[w]->mod_bvalues <= num_values);
96373c
 
96373c
         /* don't forget to null terminate it */
96373c
-        if (num_values > 0) {
96373c
+        if (num_values > 0 && normmbvp) {
96373c
             *normmbvp = NULL;
96373c
         }
96373c
     }
96373c
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
96373c
index 14ebc48e6..2af3ee18d 100644
96373c
--- a/ldap/servers/slapd/valueset.c
96373c
+++ b/ldap/servers/slapd/valueset.c
96373c
@@ -121,7 +121,9 @@ valuearray_add_valuearray_fast(Slapi_Value ***vals,
96373c
             j++;
96373c
         }
96373c
     }
96373c
-    (*vals)[nvals + j] = NULL;
96373c
+    if (*vals) {
96373c
+        (*vals)[nvals + j] = NULL;
96373c
+    }
96373c
 }
96373c
 
96373c
 void
96373c
@@ -1138,7 +1140,7 @@ slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs,
96373c
     }
96373c
 
96373c
     for (size_t i = 0; i < naddvals; i++) {
96373c
-        if (addvals[i] != NULL) {
96373c
+        if (addvals[i] != NULL && vs->va) {
96373c
             if (passin) {
96373c
                 /* We consume the values */
96373c
                 (vs->va)[vs->num] = addvals[i];
96373c
@@ -1166,7 +1168,9 @@ slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs,
96373c
             }
96373c
         }
96373c
     }
96373c
-    (vs->va)[vs->num] = NULL;
96373c
+    if (vs->va){
96373c
+        (vs->va)[vs->num] = NULL;
96373c
+    }
96373c
 
96373c
     PR_ASSERT((vs->sorted == NULL) || (vs->num < VALUESET_ARRAY_SORT_THRESHOLD) || ((vs->num >= VALUESET_ARRAY_SORT_THRESHOLD) && (vs->sorted[0] < vs->num)));
96373c
     return (rc);
96373c
diff --git a/ldap/servers/slapd/vattr.c b/ldap/servers/slapd/vattr.c
96373c
index 13e527188..f7c473ab1 100644
96373c
--- a/ldap/servers/slapd/vattr.c
96373c
+++ b/ldap/servers/slapd/vattr.c
96373c
@@ -316,13 +316,19 @@ vattr_context_check(vattr_context *c)
96373c
 static void
96373c
 vattr_context_mark(vattr_context *c)
96373c
 {
96373c
-    c->vattr_context_loop_count += 1;
96373c
+    if (c) {
96373c
+        c->vattr_context_loop_count += 1;
96373c
+    }
96373c
 }
96373c
 
96373c
 static int
96373c
 vattr_context_unmark(vattr_context *c)
96373c
 {
96373c
-    return (c->vattr_context_loop_count -= 1);
96373c
+    if (c) {
96373c
+        return (c->vattr_context_loop_count -= 1);
96373c
+    } else {
96373c
+        return 0;
96373c
+    }
96373c
 }
96373c
 
96373c
 /* modify the context structure on exit from a vattr sp function */
96373c
@@ -385,13 +391,19 @@ vattr_context_grok(vattr_context **c)
96373c
 static void
96373c
 vattr_context_set_loop_msg_displayed(vattr_context **c)
96373c
 {
96373c
-    (*c)->error_displayed = 1;
96373c
+    if (c && *c){
96373c
+        (*c)->error_displayed = 1;
96373c
+    }
96373c
 }
96373c
 
96373c
 static int
96373c
 vattr_context_is_loop_msg_displayed(vattr_context **c)
96373c
 {
96373c
-    return (*c)->error_displayed;
96373c
+    if (c && *c){
96373c
+        return (*c)->error_displayed;
96373c
+    } else {
96373c
+        return 0;
96373c
+    }
96373c
 }
96373c
 
96373c
 /*
96373c
diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c
96373c
index 5bd318df4..95cc26148 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 <limits.h>
96373c
 #include <errno.h>
96373c
 
96373c
 static char *agentx_master = NULL;
96373c
@@ -56,16 +57,22 @@ main(int argc, char *argv[])
96373c
         char *s = getenv("DEBUG_SLEEP");
96373c
         if ((s != NULL) && isdigit(*s)) {
96373c
             char *endp = NULL;
96373c
-            long secs;
96373c
+            int64_t secs;
96373c
             errno = 0;
96373c
 
96373c
-            printf("%s pid is %d\n", argv[0], getpid());
96373c
             secs = strtol(s, &endp, 10);
96373c
-            if (*endp != '\0' || errno == ERANGE) {
96373c
-                sleep(10);
96373c
-            } else {
96373c
-                sleep(secs);
96373c
+            if ( endp == s ||
96373c
+                 *endp != '\0' ||
96373c
+                 ((secs == LONG_MIN || secs == LONG_MAX) && errno == ERANGE) ||
96373c
+                 secs < 1 )
96373c
+            {
96373c
+                /* Invalid value, default to 30 seconds */
96373c
+                secs = 30;
96373c
+            } else if (secs > 3600) {
96373c
+                secs = 3600;
96373c
             }
96373c
+            printf("%s pid is %d - sleeping for %ld\n", argv[0], getpid(), secs);
96373c
+            sleep(secs);
96373c
         }
96373c
     }
96373c
 
96373c
-- 
96373c
2.13.6
96373c