andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From 1f463f1401b0adfd12cca7851d57a72fa6c58ce0 Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Wed, 5 Jun 2013 12:15:05 -0400
dc8c34
Subject: [PATCH 91/99] Coverity Fixes (Part 3)
dc8c34
dc8c34
11692 - Explicit null dereferenced (libavl/avl.c)
dc8c34
11695 - Explicit null dereferenced (cb_conn_stateless.c)
dc8c34
11696 - Explicit null dereferenced (memberof_config.c)
dc8c34
11697 - Explicit null dereferenced (memberof.c)
dc8c34
11698 - Explicit null dereferenced (memberof.c)
dc8c34
11699 - Explicit null dereferenced (memberof.c)
dc8c34
11700 - Explicit null dereferenced (memberof.c)
dc8c34
11701 - Explicit null dereferenced (cl5_api.c)
dc8c34
11702 - Explicit null dereferenced (cl5_api.c)
dc8c34
11703 - Dereference after null check (cl5_clcache.c)
dc8c34
11704 - Dereference after null check (repl5_replica_config.c)
dc8c34
11705 - Explicit null dereferenced (syntaxes/string.c)
dc8c34
11706 - Dereference after null check (plugin.c)
dc8c34
11707 - Dereference after null check (plugin.c)
dc8c34
11711 - Dereference after null check (ldif2ldbm.c)
dc8c34
11726 - Dereference after null check (valueset.c)
dc8c34
11729 - Explicit null dereferenced (libaccess/oneeval.cpp)
dc8c34
11744 - Explicit null dereferenced (dbverify.c)
dc8c34
11745 - Out-of-bounds read (linked_attrs.c)
dc8c34
11745 - Out-of-bounds read (memberof.c)
dc8c34
dc8c34
https://bugzilla.redhat.com/show_bug.cgi?id=970221
dc8c34
dc8c34
Reviewed by: richm(Thanks!)
dc8c34
(cherry picked from commit 36f25726b9723f743bc240cb44b88f74ad478ef2)
dc8c34
---
dc8c34
 ldap/libraries/libavl/avl.c                         |  7 +++++--
dc8c34
 ldap/servers/plugins/chainingdb/cb_conn_stateless.c |  2 +-
dc8c34
 ldap/servers/plugins/linkedattrs/linked_attrs.c     | 17 ++++++++++++++---
dc8c34
 ldap/servers/plugins/memberof/memberof.c            | 18 ++++++++++++++----
dc8c34
 ldap/servers/plugins/memberof/memberof_config.c     |  2 +-
dc8c34
 ldap/servers/plugins/replication/cl5_api.c          | 17 ++++++++++++++++-
dc8c34
 ldap/servers/plugins/replication/cl5_clcache.c      | 11 ++++++++---
dc8c34
 .../plugins/replication/repl5_replica_config.c      |  5 +++++
dc8c34
 ldap/servers/plugins/syntaxes/string.c              | 14 +++++++++-----
dc8c34
 ldap/servers/slapd/back-ldbm/dbverify.c             |  6 ++++--
dc8c34
 ldap/servers/slapd/back-ldbm/ldif2ldbm.c            | 16 ++++++++++++----
dc8c34
 ldap/servers/slapd/dn.c                             |  1 +
dc8c34
 ldap/servers/slapd/plugin.c                         | 21 +++++++++++++++------
dc8c34
 ldap/servers/slapd/valueset.c                       | 17 ++++++++++-------
dc8c34
 lib/libaccess/oneeval.cpp                           | 12 ++++++------
dc8c34
 15 files changed, 121 insertions(+), 45 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/libraries/libavl/avl.c b/ldap/libraries/libavl/avl.c
dc8c34
index 7577891..18c43e0 100644
dc8c34
--- a/ldap/libraries/libavl/avl.c
dc8c34
+++ b/ldap/libraries/libavl/avl.c
dc8c34
@@ -780,8 +780,11 @@ avl_getfirst( Avlnode *root )
dc8c34
 		return( 0 );
dc8c34
 
dc8c34
 	(void) avl_apply( root, avl_buildlist, (caddr_t) 0, -1, AVL_INORDER );
dc8c34
-
dc8c34
-	return( avl_list[ avl_nextlist++ ] );
dc8c34
+	if(avl_list && avl_list[avl_nextlist++]){
dc8c34
+		return avl_list[avl_nextlist];
dc8c34
+	} else {
dc8c34
+		return( NULL );
dc8c34
+	}
dc8c34
 }
dc8c34
 
dc8c34
 caddr_t
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_conn_stateless.c b/ldap/servers/plugins/chainingdb/cb_conn_stateless.c
dc8c34
index a9abc31..a85b392 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_conn_stateless.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_conn_stateless.c
dc8c34
@@ -856,7 +856,7 @@ void cb_stale_all_connections( cb_backend_instance * cb)
dc8c34
 	    else {
dc8c34
        	       	if (conn==pools[i]->conn.conn_list) {
dc8c34
        	       		pools[i]->conn.conn_list=next_conn;
dc8c34
-       	       	} else {
dc8c34
+       	       	} else if(prev_conn){
dc8c34
        	       		prev_conn->next=next_conn;
dc8c34
        	       	}
dc8c34
        	       	cb_close_and_dispose_connection(conn);
dc8c34
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
dc8c34
index ff3dc3a..4bea10f 100644
dc8c34
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
dc8c34
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
dc8c34
@@ -1231,10 +1231,21 @@ linked_attrs_load_array(Slapi_Value **array, Slapi_Attr *attr)
dc8c34
 int
dc8c34
 linked_attrs_compare(const void *a, const void *b)
dc8c34
 {
dc8c34
+        Slapi_Value *val1;
dc8c34
+        Slapi_Value *val2;
dc8c34
+        Slapi_Attr *linkattr;
dc8c34
         int rc = 0;
dc8c34
-        Slapi_Value *val1 = *((Slapi_Value **)a);
dc8c34
-        Slapi_Value *val2 = *((Slapi_Value **)b);
dc8c34
-        Slapi_Attr *linkattr = slapi_attr_new();
dc8c34
+
dc8c34
+        if(a == NULL && b != NULL){
dc8c34
+            return 1;
dc8c34
+        } else if(a != NULL && b == NULL){
dc8c34
+            return -1;
dc8c34
+        } else if(a == NULL && b == NULL){
dc8c34
+            return 0;
dc8c34
+        }
dc8c34
+        val1 = *((Slapi_Value **)a);
dc8c34
+        val2 = *((Slapi_Value **)b);
dc8c34
+        linkattr = slapi_attr_new();
dc8c34
 
dc8c34
         slapi_attr_init(linkattr, "distinguishedName");
dc8c34
 
dc8c34
diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c
dc8c34
index a3f875d..d11983b 100644
dc8c34
--- a/ldap/servers/plugins/memberof/memberof.c
dc8c34
+++ b/ldap/servers/plugins/memberof/memberof.c
dc8c34
@@ -460,7 +460,7 @@ memberof_del_dn_from_groups(Slapi_PBlock *pb, MemberOfConfig *config, Slapi_DN *
dc8c34
 	/* Loop through each grouping attribute to find groups that have
dc8c34
 	 * dn as a member.  For any matches, delete the dn value from the
dc8c34
 	 * same grouping attribute. */
dc8c34
-	for (i = 0; config->groupattrs[i]; i++)
dc8c34
+	for (i = 0; config->groupattrs && config->groupattrs[i]; i++)
dc8c34
 	{
dc8c34
 		memberof_del_dn_data data = {(char *)slapi_sdn_get_dn(sdn),
dc8c34
 		                             config->groupattrs[i]};
dc8c34
@@ -712,7 +712,7 @@ memberof_replace_dn_from_groups(Slapi_PBlock *pb, MemberOfConfig *config,
dc8c34
 	/* Loop through each grouping attribute to find groups that have
dc8c34
 	 * pre_dn as a member.  For any matches, replace pre_dn with post_dn
dc8c34
 	 * using the same grouping attribute. */
dc8c34
-	for (i = 0; config->groupattrs[i]; i++)
dc8c34
+	for (i = 0; config->groupattrs && config->groupattrs[i]; i++)
dc8c34
 	{
dc8c34
 		replace_dn_data data = {(char *)slapi_sdn_get_ndn(pre_sdn),
dc8c34
 		                        (char *)slapi_sdn_get_ndn(post_sdn),
dc8c34
@@ -2203,8 +2203,18 @@ void memberof_load_array(Slapi_Value **array, Slapi_Attr *attr)
dc8c34
  */
dc8c34
 int memberof_compare(MemberOfConfig *config, const void *a, const void *b)
dc8c34
 {
dc8c34
-	Slapi_Value *val1 = *((Slapi_Value **)a);
dc8c34
-	Slapi_Value *val2 = *((Slapi_Value **)b);
dc8c34
+	Slapi_Value *val1;
dc8c34
+	Slapi_Value *val2;
dc8c34
+
dc8c34
+	if(a == NULL && b != NULL){
dc8c34
+		return 1;
dc8c34
+	} else if(a != NULL && b == NULL){
dc8c34
+		return -1;
dc8c34
+	} else if(a == NULL && b == NULL){
dc8c34
+		return 0;
dc8c34
+	}
dc8c34
+	val1 = *((Slapi_Value **)a);
dc8c34
+	val2 = *((Slapi_Value **)b);
dc8c34
 
dc8c34
 	/* We only need to provide a Slapi_Attr here for it's syntax.  We
dc8c34
 	 * already validated all grouping attributes to use the Distinguished
dc8c34
diff --git a/ldap/servers/plugins/memberof/memberof_config.c b/ldap/servers/plugins/memberof/memberof_config.c
dc8c34
index b4d557a..3fd63a9 100644
dc8c34
--- a/ldap/servers/plugins/memberof/memberof_config.c
dc8c34
+++ b/ldap/servers/plugins/memberof/memberof_config.c
dc8c34
@@ -486,7 +486,7 @@ memberof_free_config(MemberOfConfig *config)
dc8c34
 		slapi_ch_array_free(config->groupattrs);
dc8c34
 		slapi_filter_free(config->group_filter, 1);
dc8c34
 
dc8c34
-		for (i = 0; config->group_slapiattrs[i]; i++)
dc8c34
+		for (i = 0; config->group_slapiattrs && config->group_slapiattrs[i]; i++)
dc8c34
 		{
dc8c34
 			slapi_attr_free(&config->group_slapiattrs[i]);
dc8c34
 		}
dc8c34
diff --git a/ldap/servers/plugins/replication/cl5_api.c b/ldap/servers/plugins/replication/cl5_api.c
dc8c34
index a06c43f..f17650d 100644
dc8c34
--- a/ldap/servers/plugins/replication/cl5_api.c
dc8c34
+++ b/ldap/servers/plugins/replication/cl5_api.c
dc8c34
@@ -3506,6 +3506,13 @@ static void _cl5TrimFile (Object *obj, long *numToTrim, ReplicaId cleaned_rid)
dc8c34
 			 * This change can be trimmed if it exceeds purge
dc8c34
 			 * parameters and has been seen by all consumers.
dc8c34
 			 */
dc8c34
+			if(op.csn == NULL){
dc8c34
+				slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl, "_cl5TrimFile: "
dc8c34
+						"Operation missing csn, moving on to next entry.\n");
dc8c34
+				cl5_operation_parameters_done (&op);
dc8c34
+				finished =_cl5GetNextEntry (&entry, it);
dc8c34
+				continue;
dc8c34
+			}
dc8c34
 			csn_rid = csn_get_replicaid (op.csn);
dc8c34
 			if ( (*numToTrim > 0 || _cl5CanTrim (entry.time, numToTrim)) &&
dc8c34
 				 ruv_covers_csn_strict (ruv, op.csn) )
dc8c34
@@ -3835,7 +3842,15 @@ static int  _cl5ConstructRUV (const char *replGen, Object *obj, PRBool purge)
dc8c34
     rc = _cl5GetFirstEntry (obj, &entry, &iterator, NULL);
dc8c34
     while (rc == CL5_SUCCESS)
dc8c34
     {
dc8c34
-        rid = csn_get_replicaid (op.csn);
dc8c34
+        if(op.csn){
dc8c34
+            rid = csn_get_replicaid (op.csn);
dc8c34
+        } else {
dc8c34
+            slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl, "_cl5ConstructRUV: "
dc8c34
+                "Operation missing csn, moving on to next entry.\n");
dc8c34
+            cl5_operation_parameters_done (&op);
dc8c34
+            rc = _cl5GetNextEntry (&entry, iterator);
dc8c34
+            continue;
dc8c34
+        }
dc8c34
         if(is_cleaned_rid(rid)){
dc8c34
             /* skip this entry as the rid is invalid */
dc8c34
             slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name_cl, "_cl5ConstructRUV: "
dc8c34
diff --git a/ldap/servers/plugins/replication/cl5_clcache.c b/ldap/servers/plugins/replication/cl5_clcache.c
dc8c34
index 5329b4b..67e64f5 100644
dc8c34
--- a/ldap/servers/plugins/replication/cl5_clcache.c
dc8c34
+++ b/ldap/servers/plugins/replication/cl5_clcache.c
dc8c34
@@ -750,9 +750,14 @@ clcache_skip_change ( CLC_Buffer *buf )
dc8c34
 		 */
dc8c34
 		if ( csn_time_difference(buf->buf_current_csn, cscb->local_maxcsn) == 0 &&
dc8c34
 			 (csn_get_seqnum(buf->buf_current_csn) ==
dc8c34
-				csn_get_seqnum(cscb->local_maxcsn) + 1) ) {
dc8c34
-			csn_init_by_csn ( cscb->local_maxcsn, buf->buf_current_csn );
dc8c34
-			csn_init_by_csn ( cscb->consumer_maxcsn, buf->buf_current_csn );
dc8c34
+				csn_get_seqnum(cscb->local_maxcsn) + 1) )
dc8c34
+		{
dc8c34
+			if(cscb->local_maxcsn){
dc8c34
+				csn_init_by_csn ( cscb->local_maxcsn, buf->buf_current_csn );
dc8c34
+			}
dc8c34
+			if(cscb->consumer_maxcsn){
dc8c34
+				csn_init_by_csn ( cscb->consumer_maxcsn, buf->buf_current_csn );
dc8c34
+			}
dc8c34
 			skip = 0;
dc8c34
 			break;
dc8c34
 		}
dc8c34
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
index 7c625eb..7b684e9 100644
dc8c34
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
@@ -2366,6 +2366,11 @@ delete_cleaned_rid_config(cleanruv_data *clean_data)
dc8c34
     int found = 0, i;
dc8c34
     int rc, ret, rid;
dc8c34
 
dc8c34
+    if(clean_data == NULL){
dc8c34
+        slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "delete_cleaned_rid_config: cleanruv data is NULL, "
dc8c34
+                "failed to clean the config.\n");
dc8c34
+        return;
dc8c34
+    }
dc8c34
     /*
dc8c34
      *  If there is no maxcsn, set the proper csnstr
dc8c34
      */
dc8c34
diff --git a/ldap/servers/plugins/syntaxes/string.c b/ldap/servers/plugins/syntaxes/string.c
dc8c34
index 54cd7c8..6c0da94 100644
dc8c34
--- a/ldap/servers/plugins/syntaxes/string.c
dc8c34
+++ b/ldap/servers/plugins/syntaxes/string.c
dc8c34
@@ -84,7 +84,11 @@ string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
dc8c34
 			bvfilter_norm.bv_val = alt;
dc8c34
 			alt = NULL;
dc8c34
 		}
dc8c34
-		bvfilter_norm.bv_len = strlen(bvfilter_norm.bv_val);
dc8c34
+		if(bvfilter_norm.bv_val){
dc8c34
+			bvfilter_norm.bv_len = strlen(bvfilter_norm.bv_val);
dc8c34
+		} else {
dc8c34
+			bvfilter_norm.bv_len = 0;
dc8c34
+		}
dc8c34
 	}
dc8c34
 
dc8c34
 	for ( i = 0; (bvals != NULL) && (bvals[i] != NULL); i++ ) {
dc8c34
@@ -103,7 +107,7 @@ string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
dc8c34
 							    if(retVal) {
dc8c34
 									*retVal = bvals[i];
dc8c34
 								}
dc8c34
-								slapi_ch_free ((void**)&bvfilter_norm.bv_val);
dc8c34
+								slapi_ch_free_string(&bvfilter_norm.bv_val);
dc8c34
                                 return( 0 );
dc8c34
                         }
dc8c34
                         break;
dc8c34
@@ -112,7 +116,7 @@ string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
dc8c34
 							    if(retVal) {
dc8c34
 									*retVal = bvals[i];
dc8c34
 								}
dc8c34
-								slapi_ch_free ((void**)&bvfilter_norm.bv_val);
dc8c34
+								slapi_ch_free_string(&bvfilter_norm.bv_val);
dc8c34
                                 return( 0 );
dc8c34
                         }
dc8c34
                         break;
dc8c34
@@ -121,14 +125,14 @@ string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
dc8c34
 							    if(retVal) {
dc8c34
 									*retVal = bvals[i];
dc8c34
 								}
dc8c34
-								slapi_ch_free ((void**)&bvfilter_norm.bv_val);
dc8c34
+								slapi_ch_free_string(&bvfilter_norm.bv_val);
dc8c34
                                 return( 0 );
dc8c34
                         }
dc8c34
                         break;
dc8c34
                 }
dc8c34
         }
dc8c34
 
dc8c34
-	slapi_ch_free ((void**)&bvfilter_norm.bv_val);
dc8c34
+	slapi_ch_free_string(&bvfilter_norm.bv_val);
dc8c34
 	return( -1 );
dc8c34
 }
dc8c34
 
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/dbverify.c b/ldap/servers/slapd/back-ldbm/dbverify.c
dc8c34
index 43fc9d5..ffd5900 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/dbverify.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/dbverify.c
dc8c34
@@ -119,9 +119,11 @@ dbverify_ext( ldbm_instance *inst, int verbose )
dc8c34
             char *p = NULL;
dc8c34
             p = strstr(filep, LDBM_FILENAME_SUFFIX); /* since already checked,
dc8c34
                                                         it must have it */
dc8c34
-            *p = '\0';
dc8c34
+            if(p)
dc8c34
+                *p = '\0';
dc8c34
             ainfo_get( inst->inst_be, filep+1, &ai );
dc8c34
-            *p = '.';
dc8c34
+            if(p)
dc8c34
+                *p = '.';
dc8c34
             if (ai->ai_key_cmp_fn) {
dc8c34
                 dbp->app_private = (void *)ai->ai_key_cmp_fn;
dc8c34
                 dbp->set_bt_compare(dbp, dblayer_bt_compare);
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
dc8c34
index c802ff2..47e0269 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
dc8c34
@@ -2246,15 +2246,23 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
dc8c34
          * Update the Virtual List View indexes
dc8c34
          */
dc8c34
         for ( vlvidx = 0; vlvidx < numvlv; vlvidx++ ) {
dc8c34
+            char *ai = "Unknown index";
dc8c34
+
dc8c34
             if ( g_get_shutdown() || c_get_shutdown() ) {
dc8c34
                 goto err_out;
dc8c34
             }
dc8c34
+            if(indexAttrs){
dc8c34
+                  if(indexAttrs[vlvidx]){
dc8c34
+                      ai = indexAttrs[vlvidx];
dc8c34
+                  }
dc8c34
+            }
dc8c34
             if (!run_from_cmdline) {
dc8c34
                 rc = dblayer_txn_begin(li, NULL, &txn);
dc8c34
                 if (0 != rc) {
dc8c34
+
dc8c34
                     LDAPDebug(LDAP_DEBUG_ANY,
dc8c34
                       "%s: ERROR: failed to begin txn for update index '%s'\n",
dc8c34
-                      inst->inst_name, indexAttrs[vlvidx], 0);
dc8c34
+                      inst->inst_name, ai, 0);
dc8c34
                     LDAPDebug(LDAP_DEBUG_ANY,
dc8c34
                         "%s: Error %d: %s\n", inst->inst_name, rc,
dc8c34
                         dblayer_strerror(rc));
dc8c34
@@ -2262,7 +2270,7 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
dc8c34
                         slapi_task_log_notice(task,
dc8c34
                          "%s: ERROR: failed to begin txn for update index '%s' "
dc8c34
                          "(err %d: %s)", inst->inst_name,
dc8c34
-                         indexAttrs[vlvidx], rc, dblayer_strerror(rc));
dc8c34
+                         ai, rc, dblayer_strerror(rc));
dc8c34
                     }
dc8c34
                     return_value = -2;
dc8c34
                     goto err_out;
dc8c34
@@ -2281,7 +2289,7 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
dc8c34
                 if (0 != rc) {
dc8c34
                     LDAPDebug(LDAP_DEBUG_ANY,
dc8c34
                       "%s: ERROR: failed to commit txn for update index '%s'\n",
dc8c34
-                      inst->inst_name, indexAttrs[vlvidx], 0);
dc8c34
+                      inst->inst_name, ai, 0);
dc8c34
                     LDAPDebug(LDAP_DEBUG_ANY,
dc8c34
                         "%s: Error %d: %s\n", inst->inst_name, rc,
dc8c34
                         dblayer_strerror(rc));
dc8c34
@@ -2289,7 +2297,7 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
dc8c34
                         slapi_task_log_notice(task,
dc8c34
                         "%s: ERROR: failed to commit txn for update index '%s' "
dc8c34
                         "(err %d: %s)", inst->inst_name,
dc8c34
-                        indexAttrs[vlvidx], rc, dblayer_strerror(rc));
dc8c34
+                        ai, rc, dblayer_strerror(rc));
dc8c34
                     }
dc8c34
                     return_value = -2;
dc8c34
                     goto err_out;
dc8c34
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
dc8c34
index 2f50e97..dda439b 100644
dc8c34
--- a/ldap/servers/slapd/dn.c
dc8c34
+++ b/ldap/servers/slapd/dn.c
dc8c34
@@ -2614,3 +2614,4 @@ slapi_sdn_get_size(const Slapi_DN *sdn)
dc8c34
     }
dc8c34
     return sz;
dc8c34
 }
dc8c34
+
dc8c34
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
dc8c34
index 436cc02..0a4f4e0 100644
dc8c34
--- a/ldap/servers/slapd/plugin.c
dc8c34
+++ b/ldap/servers/slapd/plugin.c
dc8c34
@@ -1493,15 +1493,24 @@ int
dc8c34
 slapi_berval_cmp (const struct berval* L, const struct berval* R) /* JCM - This does not belong here. But, where should it go? */
dc8c34
 {
dc8c34
     int result = 0;
dc8c34
+
dc8c34
+    if(L == NULL && R != NULL){
dc8c34
+        return 1;
dc8c34
+    } else if(L != NULL && R == NULL){
dc8c34
+        return -1;
dc8c34
+    } else if(L == NULL && R == NULL){
dc8c34
+        return 0;
dc8c34
+    }
dc8c34
     if (L->bv_len < R->bv_len) {
dc8c34
-	result = memcmp (L->bv_val, R->bv_val, L->bv_len);
dc8c34
-	if (result == 0)
dc8c34
-	  result = -1;
dc8c34
+        result = memcmp (L->bv_val, R->bv_val, L->bv_len);
dc8c34
+        if (result == 0)
dc8c34
+            result = -1;
dc8c34
     } else {
dc8c34
-	result = memcmp (L->bv_val, R->bv_val, R->bv_len);
dc8c34
-	if (result == 0 && (L->bv_len > R->bv_len))
dc8c34
-	  result = 1;
dc8c34
+        result = memcmp (L->bv_val, R->bv_val, R->bv_len);
dc8c34
+        if (result == 0 && (L->bv_len > R->bv_len))
dc8c34
+            result = 1;
dc8c34
     }
dc8c34
+
dc8c34
     return result;
dc8c34
 }
dc8c34
 
dc8c34
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
dc8c34
index a91256c..f04acc3 100644
dc8c34
--- a/ldap/servers/slapd/valueset.c
dc8c34
+++ b/ldap/servers/slapd/valueset.c
dc8c34
@@ -190,20 +190,23 @@ valuearray_add_valuearray(Slapi_Value ***vals, Slapi_Value **addvals, PRUint32 f
dc8c34
 {
dc8c34
     int valslen;
dc8c34
     int addvalslen;
dc8c34
-	int maxvals;
dc8c34
+    int maxvals;
dc8c34
 
dc8c34
-	addvalslen= valuearray_count(addvals);
dc8c34
+    if(vals == NULL){
dc8c34
+        return;
dc8c34
+    }
dc8c34
+    addvalslen= valuearray_count(addvals);
dc8c34
     if(*vals == NULL)
dc8c34
     {
dc8c34
-		valslen= 0;
dc8c34
-		maxvals= 0;
dc8c34
+        valslen= 0;
dc8c34
+        maxvals= 0;
dc8c34
     }
dc8c34
     else
dc8c34
     {
dc8c34
-		valslen= valuearray_count(*vals);
dc8c34
-		maxvals= valslen+1;
dc8c34
+        valslen= valuearray_count(*vals);
dc8c34
+        maxvals= valslen+1;
dc8c34
     }
dc8c34
-	valuearray_add_valuearray_fast(vals,addvals,valslen,addvalslen,&maxvals,1/*Exact*/,flags & SLAPI_VALUE_FLAG_PASSIN);
dc8c34
+    valuearray_add_valuearray_fast(vals,addvals,valslen,addvalslen,&maxvals,1/*Exact*/,flags & SLAPI_VALUE_FLAG_PASSIN);
dc8c34
 }
dc8c34
 
dc8c34
 int
dc8c34
diff --git a/lib/libaccess/oneeval.cpp b/lib/libaccess/oneeval.cpp
dc8c34
index eff4e10..a6d3bbd 100644
dc8c34
--- a/lib/libaccess/oneeval.cpp
dc8c34
+++ b/lib/libaccess/oneeval.cpp
dc8c34
@@ -381,20 +381,19 @@ ACLEvalBuildContext(
dc8c34
     /* 	  Loop through all the ACLs in the list    */
dc8c34
     while (wrapper)        
dc8c34
     {
dc8c34
-	acl = wrapper->acl;
dc8c34
+        acl = wrapper->acl;
dc8c34
         ace = acl->expr_list_head;
dc8c34
 
dc8c34
         while (ace)    /* Loop through all the ACEs in this ACL    */
dc8c34
         {
dc8c34
-
dc8c34
             /* allocate a new ace list entry and link it in    to the ordered
dc8c34
              * list.
dc8c34
              */
dc8c34
             new_ace = (ACLAceEntry_t *)PERM_CALLOC(sizeof(ACLAceEntry_t));
dc8c34
             if (new_ace == (ACLAceEntry_t *)NULL) {
dc8c34
-		nserrGenerate(errp, ACLERRNOMEM, ACLERR4020, ACL_Program, 1,
dc8c34
-		XP_GetAdminStr(DBT_EvalBuildContextUnableToAllocAceEntry));
dc8c34
-		goto error;
dc8c34
+                nserrGenerate(errp, ACLERRNOMEM, ACLERR4020, ACL_Program, 1,
dc8c34
+                XP_GetAdminStr(DBT_EvalBuildContextUnableToAllocAceEntry));
dc8c34
+                goto error;
dc8c34
             }
dc8c34
             new_ace->acep    = ace;
dc8c34
             ace_cnt++;
dc8c34
@@ -402,7 +401,8 @@ ACLEvalBuildContext(
dc8c34
             if (cache->acelist == NULL)
dc8c34
                 cache->acelist = acelast    = new_ace;
dc8c34
             else {
dc8c34
-                acelast->next  = new_ace;
dc8c34
+                if(acelast)
dc8c34
+                    acelast->next  = new_ace;
dc8c34
                 acelast        = new_ace;
dc8c34
                 new_ace->acep  = ace;
dc8c34
             }
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34