From 3f61b3eabaa23f1df0c15a251ff0bbfaf69e6ba4 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Mon, 10 Nov 2008 18:18:22 +0000
Subject: [PATCH] ITS#5742

---
 CHANGES                |  1 +
 servers/slapd/result.c | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/CHANGES b/CHANGES
index 36a3a3ca28..d5387d8b5d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,7 @@ OpenLDAP 2.4.13 Engineering
 	Added slapd-bdb/hdb dbpagesize keyword
 	Added slapd-bdb/hdb checksum keyword
 	Fixed slapo-chain/translucent back-config support (ITS#5736)
+	Fixed slapd-chain segv with search references (ITS#5742)
 	Added slapo-constraint support for LDAP URI constraints (ITS#5704)
 	Added slapo-constraint support for constraining rename (ITS#5703)
 	Added slapo-constraint support for relax control (ITS#5705)
diff --git a/servers/slapd/result.c b/servers/slapd/result.c
index 2912143dd4..34b79b4ebf 100644
--- a/servers/slapd/result.c
+++ b/servers/slapd/result.c
@@ -1273,6 +1273,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 	BerElement	*ber = (BerElement *) &berbuf;
 	int rc = 0;
 	int bytes;
+	char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)";
 
 	AttributeDescription *ad_ref = slap_schema.si_ad_ref;
 	AttributeDescription *ad_entry = slap_schema.si_ad_entry;
@@ -1287,7 +1288,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 
 	Debug( LDAP_DEBUG_TRACE,
 		"=> send_search_reference: dn=\"%s\"\n",
-		rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
+		edn, 0, 0 );
 
 	if (  rs->sr_entry && ! access_allowed( op, rs->sr_entry,
 		ad_entry, NULL, ACL_READ, NULL ) )
@@ -1313,7 +1314,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 	if( op->o_domain_scope ) {
 		Debug( LDAP_DEBUG_ANY,
 			"send_search_reference: domainScope control in (%s)\n", 
-			rs->sr_entry->e_dn, 0, 0 );
+			edn, 0, 0 );
 		rc = 0;
 		goto rel;
 	}
@@ -1321,7 +1322,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 	if( rs->sr_ref == NULL ) {
 		Debug( LDAP_DEBUG_ANY,
 			"send_search_reference: null ref in (%s)\n", 
-			rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
+			edn, 0, 0 );
 		rc = 1;
 		goto rel;
 	}
@@ -1371,6 +1372,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 
 	rc = 0;
 	if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
+		assert( rs->sr_entry != NULL );
 		be_entry_release_rw( op, rs->sr_entry, 0 );
 		rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
 		rs->sr_entry = NULL;
@@ -1520,8 +1522,8 @@ int slap_read_controls(
 	LDAPControl c;
 	Operation myop;
 
-	Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
-		oid->bv_val, e->e_dn, 0 );
+	Debug( LDAP_DEBUG_ANY, "%s slap_read_controls: (%s) %s\n",
+		op->o_log_prefix, oid->bv_val, e->e_dn );
 
 	rs->sr_entry = e;
 	rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
-- 
GitLab