Skip to content

Commit c202e80

Browse files
committed
ext/ldap: ldap_read/ldap_list/ldap_search update.
checks sizelimit/timelimit checks and attrsonly from int to bool.
1 parent 790286a commit c202e80

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

ext/ldap/ldap.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14481448
zend_string *base_dn_str = NULL;
14491449
HashTable *filter_ht = NULL;
14501450
zend_string *filter_str = NULL;
1451-
zend_long attrsonly, sizelimit, timelimit, deref;
1451+
zend_long sizelimit = 0, timelimit = 0, deref = LDAP_DEREF_NEVER;
1452+
bool attrsonly = false;
14521453
HashTable *server_controls_ht = NULL;
14531454
char **ldap_attrs = NULL;
14541455
ldap_linkdata *ld = NULL;
@@ -1465,13 +1466,28 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14651466
Z_PARAM_ARRAY_HT_OR_STR(filter_ht, filter_str)
14661467
Z_PARAM_OPTIONAL
14671468
Z_PARAM_ARRAY_EX(attrs, 0, 1)
1468-
Z_PARAM_LONG(attrsonly)
1469+
Z_PARAM_BOOL(attrsonly)
14691470
Z_PARAM_LONG(sizelimit)
14701471
Z_PARAM_LONG(timelimit)
14711472
Z_PARAM_LONG(deref)
14721473
Z_PARAM_ARRAY_HT_EX(server_controls_ht, 1, 1)
14731474
ZEND_PARSE_PARAMETERS_END();
14741475

1476+
if (sizelimit < -1 || sizelimit > INT_MAX) {
1477+
zend_argument_value_error(6, "must be between -1 and %d", INT_MAX);
1478+
RETURN_THROWS();
1479+
}
1480+
1481+
if (timelimit < -1 || timelimit > INT_MAX) {
1482+
zend_argument_value_error(7, "must be between -1 and %d", INT_MAX);
1483+
RETURN_THROWS();
1484+
}
1485+
1486+
if (deref < LDAP_DEREF_NEVER || deref > LDAP_DEREF_ALWAYS) {
1487+
zend_argument_value_error(8, "must be one of the LDAP_DEREF_* constants");
1488+
RETURN_THROWS();
1489+
}
1490+
14751491
/* Reverse -> fall through */
14761492
switch (argcount) {
14771493
case 9:
@@ -1485,7 +1501,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14851501
ldap_sizelimit = sizelimit;
14861502
ZEND_FALLTHROUGH;
14871503
case 5:
1488-
ldap_attrsonly = attrsonly;
1504+
ldap_attrsonly = attrsonly ? 1 : 0;
14891505
ZEND_FALLTHROUGH;
14901506
default:
14911507
break;

ext/ldap/ldap.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ function ldap_sasl_bind(LDAP\Connection $ldap, ?string $dn = null, #[\SensitiveP
646646
#endif
647647

648648
/** @param LDAP\Connection|array $ldap */
649-
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null): LDAP\Result|array|false {}
649+
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], bool $attributes_only = false, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null): LDAP\Result|array|false {}
650650

651651
/** @param LDAP\Connection|array $ldap */
652-
function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null): LDAP\Result|array|false {}
652+
function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], bool $attributes_only = false, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null): LDAP\Result|array|false {}
653653

654654
/** @param LDAP\Connection|array $ldap */
655-
function ldap_search($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null): LDAP\Result|array|false {}
655+
function ldap_search($ldap, array|string $base, array|string $filter, array $attributes = [], bool $attributes_only = false, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null): LDAP\Result|array|false {}
656656

657657
function ldap_free_result(LDAP\Result $result): bool {}
658658

ext/ldap/ldap_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)