Bug #81119 [Opn->Ver]: GMP operators throw errors with wrong parameter names
| From: | cmb@php.net | Date: | Wed, 09 Jun 2021 15:51:16 +0000 |
| Subject: | Bug #81119 [Opn->Ver]: GMP operators throw errors with wrong parameter names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234313@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81119&edit=1
ID: 81119
Updated by: cmb@php.net
Reported by: lauri dot kentta+php-bugs at gmail dot com
Summary: GMP operators throw errors with wrong parameter
names
-Status: Open
+Status: Verified
Type: Bug
Package: GNU MP related
-PHP Version: master-Git-2021-06-09 (Git)
+PHP Version: PHP 8.0
Block user comment: N
Private report: N
New Comment:
<https://3v4l.org/J00BTp>
Previous Comments:
------------------------------------------------------------------------
[2021-06-09 15:28:03] lauri dot kentta+php-bugs at gmail dot com
Description:
------------
When using GMP class operators such as + or < with an invalid second value (such as non-numeric
string or array), the exception picks up parameter name from the outer scope. Operator parameter
probably doesn't have any meaningful name. The bad messages come from ext/gmp/gmp.c, function
convert_to_gmp, lines 623 and 632.
Just run (gmp_init(1) < "x") inside a function, and you'll find the second
function parameter name in the error message.
Test script:
---------------
<?php
function test($f) {
try {
$f();
echo "No error?\n";
} catch (TypeError|ValueError $e) {
if (strpos($e->getMessage(), '($WRONG_SCOPE_')) {
echo "Bad error! ", $e->getMessage(), "\n";
} else {
echo "Good error.\n";
}
}
}
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) < "x");
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) < []);
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) + "x");
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) + []);
Expected result:
----------------
Good error.
Good error.
Good error.
Good error.
Actual result:
--------------
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) is not an integer string
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) must be of type GMP|string|int, array given
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) is not an integer string
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) must be of type GMP|string|int, array given
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81119&edit=1