Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ PHP NEWS
- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)

- LDAP:
. Fixed bug GH-22108 (Regression in 8.5: float values are treated as invalid
when updating LDAP values). (Juan Versolato Lopes)

- MBString:
. Fixed stack overflow in mb_check_encoding() and mb_convert_encoding() with
deeply nested arrays. (Eyüp Can Akman)
Expand Down
12 changes: 12 additions & 0 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ static zend_string* php_ldap_try_get_ldap_value_from_zval(zval *zv) {
return ZSTR_INIT_LITERAL("TRUE", false);
case IS_FALSE:
return ZSTR_INIT_LITERAL("FALSE", false);
case IS_DOUBLE: {
/* LDAP has no float syntax, but integral floats (e.g. the result of
* round(), or an int that overflowed) are accepted as integers */
double dval = Z_DVAL_P(zv);
if (zend_finite(dval) && dval == floor(dval)) {
if (dval == 0) {
return ZSTR_CHAR('0');
}
return zend_strpprintf(0, "%.0F", dval);
}
ZEND_FALLTHROUGH;
}
default:
zend_type_error("LDAP value must be of type string|int|bool, %s given", zend_zval_value_name(zv));
return NULL;
Expand Down
57 changes: 57 additions & 0 deletions ext/ldap/tests/gh22108.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
GH-22108 (Integral float values are rejected when modifying LDAP entries)
--EXTENSIONS--
ldap
--SKIPIF--
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";

$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
insert_dummy_data($link, $base);

var_dump(ldap_mod_replace($link, "cn=userA,$base", [
"description" => [round(20400.4), -3.0, -0.0, 1e20],
]));

$entries = ldap_get_entries(
$link,
ldap_read($link, "cn=userA,$base", "(objectClass=*)", ["description"])
);
$values = $entries[0]["description"];
unset($values["count"]);
sort($values);
var_dump($values);

foreach ([1.5, NAN, INF] as $value) {
try {
ldap_mod_replace($link, "cn=userA,$base", ["description" => $value]);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
}
?>
--CLEAN--
<?php
require "connect.inc";

$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);

remove_dummy_data($link, $base);
?>
--EXPECT--
bool(true)
array(4) {
[0]=>
string(2) "-3"
[1]=>
string(1) "0"
[2]=>
string(5) "20400"
[3]=>
string(21) "100000000000000000000"
}
LDAP value must be of type string|int|bool, float given
LDAP value must be of type string|int|bool, float given
LDAP value must be of type string|int|bool, float given
Loading