diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index e6ea4d908af5..2b3cb0e8a706 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -564,6 +564,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra num_keys = zend_hash_num_elements(Z_ARRVAL_P(val)); sort_keys = safe_emalloc((num_keys+1), sizeof(LDAPSortKey*), 0); + memset(sort_keys, 0, (num_keys+1) * sizeof(LDAPSortKey*)); tmpstrings1 = safe_emalloc(num_keys, sizeof(zend_string*), 0); tmpstrings2 = safe_emalloc(num_keys, sizeof(zend_string*), 0); num_tmpstrings1 = 0; diff --git a/ext/ldap/tests/ldap_sort_control_missing_attr.phpt b/ext/ldap/tests/ldap_sort_control_missing_attr.phpt new file mode 100644 index 000000000000..0d6c3921f008 --- /dev/null +++ b/ext/ldap/tests/ldap_sort_control_missing_attr.phpt @@ -0,0 +1,30 @@ +--TEST-- +ldap_search(): malformed sort control (sort key missing "attr") must not free uninitialized memory +--EXTENSIONS-- +ldap +--FILE-- + LDAP_CONTROL_SORTREQUEST, + 'value' => [ + ['attr' => 'cn'], + ['reverse' => true], + ], + ], + ]); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +echo "ok\n"; +?> +--EXPECT-- +ldap_search(): Sort key list must have an "attr" key +ok