From b0baeb61deec0a5ba35e1c8d5f6e11bad9b4f193 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Fri, 17 Dec 2010 18:16:05 +0000
Subject: [PATCH] ITS#6602

---
 CHANGES                     |  1 +
 libraries/libldap/request.c | 10 ++++------
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/CHANGES b/CHANGES
index 50f70c3d34..eaa6ea62bf 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ OpenLDAP 2.4.24 Engineering
 	Fixed libldap dnssrv port format specifier (ITS#6644)
 	Fixed libldap GnuTLS hang on socket close (ITS#6673)
 	Fixed libldap sasl partial write handling (ITS#6639)
+	Fixed libldap referral chasing (ITS#6602)
 	Fixed libldap url parsing with NULL host (ITS#6653)
 	Fixed liblutil getpass prompts (ITS#6702)
 	Fixed ldapsearch segfault with deref (ITS#6638)
diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c
index 287ce47109..183e0d76af 100644
--- a/libraries/libldap/request.c
+++ b/libraries/libldap/request.c
@@ -1044,6 +1044,7 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char *
 	LDAPConn	*lc;
 	int			 rc, count, i, j, id;
 	LDAPreqinfo  rinfo;
+	LDAP_NEXTREF_PROC	*nextref_proc = ld->ld_nextref_proc ? ld->ld_nextref_proc : ldap_int_nextref;
 
 	ld->ld_errno = LDAP_SUCCESS;	/* optimistic */
 	*hadrefp = 0;
@@ -1079,15 +1080,12 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char *
 	refarray = refs;
 	refs = NULL;
 
-	if ( ld->ld_nextref_proc == NULL ) {
-		ld->ld_nextref_proc = ldap_int_nextref;
-	}
-
 	/* parse out & follow referrals */
+	/* NOTE: if nextref_proc == ldap_int_nextref, params is ignored */
 	i = -1;
-	for ( ld->ld_nextref_proc( ld, &refarray, &i, ld->ld_nextref_params );
+	for ( nextref_proc( ld, &refarray, &i, ld->ld_nextref_params );
 			i != -1;
-			ld->ld_nextref_proc( ld, &refarray, &i, ld->ld_nextref_params ) )
+			nextref_proc( ld, &refarray, &i, ld->ld_nextref_params ) )
 	{
 
 		/* Parse the referral URL */
-- 
GitLab