From cee392aae4115e623d32552167e55e91d91da138 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Tue, 30 Jun 2026 11:03:03 +0530 Subject: [PATCH 1/2] ext/ldap: fix ldap_explode_dn result ordering and simplify count handling --- ext/ldap/ldap.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 9befe134cded..d2e25b9d419d 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -2202,6 +2202,7 @@ PHP_FUNCTION(ldap_explode_dn) zend_long with_attrib; char *dn, **ldap_value; size_t dn_len; + int i, count; if (zend_parse_parameters(ZEND_NUM_ARGS(), "pl", &dn, &dn_len, &with_attrib) != SUCCESS) { RETURN_THROWS(); @@ -2213,11 +2214,16 @@ PHP_FUNCTION(ldap_explode_dn) } array_init(return_value); - int i; - for (i = 0; ldap_value[i] != NULL; i++) { + + i = 0; + while (ldap_value[i] != NULL) i++; + count = i; + + add_assoc_long(return_value, "count", count); + + for (i = 0; i < count; i++) { add_index_string(return_value, i, ldap_value[i]); } - add_assoc_long(return_value, "count", i); ldap_memvfree((void **)ldap_value); } From b4a1588ff3498b20d3897047962f24a4a15c3598 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Tue, 30 Jun 2026 12:08:31 +0530 Subject: [PATCH 2/2] ext/ldap: fix ldap_explode_dn result ordering and simplify count handling --- ext/ldap/tests/ldap_explode_dn.phpt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/ldap/tests/ldap_explode_dn.phpt b/ext/ldap/tests/ldap_explode_dn.phpt index 047078c7beb7..2012506c3ef0 100644 --- a/ext/ldap/tests/ldap_explode_dn.phpt +++ b/ext/ldap/tests/ldap_explode_dn.phpt @@ -34,16 +34,18 @@ echo "Done\n"; ?> --EXPECT-- array(4) { + ["count"]=> + int(3) [0]=> string(6) "cn=bob" [1]=> string(10) "dc=example" [2]=> string(6) "dc=com" - ["count"]=> - int(3) } array(5) { + ["count"]=> + int(4) [0]=> string(6) "cn=bob" [1]=> @@ -52,20 +54,20 @@ array(5) { string(10) "dc=example" [3]=> string(6) "dc=com" - ["count"]=> - int(4) } array(4) { + ["count"]=> + int(3) [0]=> string(3) "bob" [1]=> string(7) "example" [2]=> string(3) "com" - ["count"]=> - int(3) } array(5) { + ["count"]=> + int(4) [0]=> string(3) "bob" [1]=> @@ -74,8 +76,6 @@ array(5) { string(7) "example" [3]=> string(3) "com" - ["count"]=> - int(4) } bool(false) bool(false)