diff --git a/NEWS b/NEWS index 68b1dcaecf3b..de2541d249a0 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index edeab9ed1aea..41a51fbd5f23 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -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; diff --git a/ext/ldap/tests/gh22108.phpt b/ext/ldap/tests/gh22108.phpt new file mode 100644 index 000000000000..b5428e51dbc4 --- /dev/null +++ b/ext/ldap/tests/gh22108.phpt @@ -0,0 +1,57 @@ +--TEST-- +GH-22108 (Integral float values are rejected when modifying LDAP entries) +--EXTENSIONS-- +ldap +--SKIPIF-- + +--FILE-- + [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-- + +--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