Skip to content

Commit d3e65d5

Browse files
committed
ext/ldap: Throw a ValueError when passing an unknown option
1 parent 18fca34 commit d3e65d5

5 files changed

+31
-7
lines changed

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP 8.5 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- LDAP:
23+
. ldap_get_option() and ldap_set_option() now throw a ValueError when
24+
passing an invalid option.
25+
2226
- SPL:
2327
. ArrayObject no longer accepts enums, as modifying the $name or $value
2428
properties can break engine assumptions.

ext/ldap/ldap.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,8 @@ PHP_FUNCTION(ldap_get_option)
30093009
case LDAP_OPT_API_FEATURE_INFO:
30103010
*/
30113011
default:
3012-
RETURN_FALSE;
3012+
zend_argument_value_error(2, "must be a valid LDAP option");
3013+
RETURN_THROWS();
30133014
}
30143015
RETURN_TRUE;
30153016
}
@@ -3207,7 +3208,8 @@ PHP_FUNCTION(ldap_set_option)
32073208
}
32083209
} break;
32093210
default:
3210-
RETURN_FALSE;
3211+
zend_argument_value_error(2, "must be a valid LDAP option");
3212+
RETURN_THROWS();
32113213
}
32123214
RETURN_TRUE;
32133215
}

ext/ldap/tests/ldap_get_option_package_basic.phpt

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ $link = ldap_connect($uri);
1111

1212
$result = ldap_get_option($link, LDAP_OPT_X_TLS_PACKAGE, $optionval);
1313
var_dump(in_array($optionval, ['GnuTLS', 'OpenSSL', 'MozNSS']));
14-
// This is a read-only option.
15-
var_dump(ldap_set_option($link, LDAP_OPT_X_TLS_PACKAGE, 'foo'));
14+
1615
?>
1716
--EXPECT--
1817
bool(true)
19-
bool(false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
ldap_(g|s)et_option() with non existing option
3+
--EXTENSIONS--
4+
ldap
5+
--FILE--
6+
<?php
7+
8+
$ldap = ldap_connect('ldap://127.0.0.1:3333');
9+
try {
10+
var_dump(ldap_set_option($ldap, 999999, "bogus"));
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
14+
try {
15+
var_dump(ldap_get_option($ldap, 999999, $value));
16+
} catch (Throwable $e) {
17+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
18+
}
19+
?>
20+
--EXPECT--
21+
ValueError: ldap_set_option(): Argument #2 ($option) must be a valid LDAP option
22+
ValueError: ldap_get_option(): Argument #2 ($option) must be a valid LDAP option

ext/ldap/tests/ldap_set_option_error.phpt

-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ foreach ($controls as $control) {
3333
}
3434
}
3535

36-
var_dump(ldap_set_option($link, 999999, 999999));
3736
?>
3837
--EXPECT--
3938
bool(false)
4039
ValueError: ldap_set_option(): Control must have an "oid" key
4140
TypeError: ldap_set_option(): Argument #3 ($value) must contain only arrays, where each array is a control
4241
TypeError: ldap_set_option(): Argument #3 ($value) must be of type array for the LDAP_OPT_CLIENT_CONTROLS option, string given
43-
bool(false)

0 commit comments

Comments
 (0)