diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 35e4e4321c4..17f008ae539 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -1402,7 +1402,7 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in /* {{{ php_ldap_do_search */ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) { - zval *link, *attrs = NULL, *attr, *serverctrls = NULL; + zval *link, *attrs = NULL, *serverctrls = NULL; zend_string *base_dn_str, *filter_str; HashTable *base_dn_ht, *filter_ht; zend_long attrsonly, sizelimit, timelimit, deref; @@ -1414,7 +1414,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) LDAPControl **lserverctrls = NULL; int ldap_attrsonly = 0, ldap_sizelimit = -1, ldap_timelimit = -1, ldap_deref = -1; int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1; - int num_attribs = 0, ret = 1, i, ldap_errno, argcount = ZEND_NUM_ARGS(); + int ret = 1, ldap_errno, argcount = ZEND_NUM_ARGS(); ZEND_PARSE_PARAMETERS_START(3, 9) Z_PARAM_ZVAL(link) @@ -1444,30 +1444,46 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) case 5: ldap_attrsonly = attrsonly; ZEND_FALLTHROUGH; - case 4: - num_attribs = zend_hash_num_elements(Z_ARRVAL_P(attrs)); - ldap_attrs = safe_emalloc((num_attribs+1), sizeof(char *), 0); - - for (i = 0; i "attrib2", + "attrib3", +]; +try { + var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $not_list)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +$not_list_of_strings = [ + "attrib1", + 42, + "attrib3", +]; +try { + var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $not_list_of_strings)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +$list_of_strings_with_null_byte = [ + "attrib1", + "attrib_with\0nul_byte", + "attrib3", +]; +try { + var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $list_of_strings_with_null_byte)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +$str = "attrib_with\0nul_byte"; + +$list_with_ref_nul_byte = [ + "attrib1", + &$str, + "attrib3", +]; +try { + var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $list_with_ref_nul_byte)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +ValueError: ldap_list(): Argument #4 ($attributes) must be a list +TypeError: ldap_list(): Argument #4 ($attributes) must be a list of strings, int given +ValueError: ldap_list(): Argument #4 ($attributes) must not contain strings with any null bytes +ValueError: ldap_list(): Argument #4 ($attributes) must not contain strings with any null bytes diff --git a/ext/ldap/tests/ldap_search_error.phpt b/ext/ldap/tests/ldap_search_error.phpt index 4e775ad13d6..b147b69766f 100644 --- a/ext/ldap/tests/ldap_search_error.phpt +++ b/ext/ldap/tests/ldap_search_error.phpt @@ -19,8 +19,12 @@ $filter = "(dc=*)"; $result = ldap_search($link, $dn, $filter); var_dump($result); -$result = ldap_search($link, $dn, $filter, array(1 => 'top')); -var_dump($result); +try { + $result = ldap_search($link, $dn, $filter, array(1 => 'top')); + var_dump($result); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} try { ldap_search(array(), $dn, $filter, array('top')); @@ -56,9 +60,7 @@ try { --EXPECTF-- Warning: ldap_search(): Search: No such object in %s on line %d bool(false) - -Warning: ldap_search(): Array initialization wrong in %s on line %d -bool(false) +ldap_search(): Argument #4 ($attributes) must be a list ldap_search(): Argument #1 ($ldap) must not be empty ldap_search(): Argument #2 ($base) must have the same number of elements as the links array ldap_search(): Argument #3 ($filter) must have the same number of elements as the links array