diff --git a/CHANGES b/CHANGES
index 4e28e98117dce099634fc704baa963a316ea46d1..dc99db532604369c5d6860e0c571171195e56257 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,8 @@ Changes included in OpenLDAP 1.2
 	CVS Tag: OPENLDAP_REL_ENG_1_2
 	Fixed slapd/ldbm/add cache set state deadlock bug
 	Fixed slapd/ldbm/add,modrdn,delete e_ndn handling
-	Fixed -lldap/ldap_init()
+	Fixed -lldap/ldap_init() bug
+	Fixed -lldap/ldap_sort_entries() zero entries bug
 	Updated ldap_open(3) man page to note ldap_init() is preferred.
 	Updated internal thread library
 	Updated slapd/back-shell to use void* private and pid_t
diff --git a/libraries/libldap/sort.c b/libraries/libldap/sort.c
index 0e2996cac06dbffc25e0c06387d1e1e789439d90..9a4427b47309c349059f942ad4d25d09665f4f98 100644
--- a/libraries/libldap/sort.c
+++ b/libraries/libldap/sort.c
@@ -93,6 +93,18 @@ ldap_sort_entries(
 
 	count = ldap_count_entries( ld, *chain );
 
+
+	if ( count < 0 ) {
+		if( ld != NULL ) {
+			ld->ld_errno = LDAP_PARAM_ERROR;
+		}
+		return -1;
+
+	} else if ( count < 2 ) {
+		/* zero or one entries -- already sorted! */
+		return 0;
+	}
+
 	if ( (et = (struct entrything *) malloc( count *
 	    sizeof(struct entrything) )) == NULL ) {
 		ld->ld_errno = LDAP_NO_MEMORY;