Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-15968: Avoid converting objects to strings in operator calculations. #16021

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ static zend_result bcmath_number_parse_num(zval *zv, zend_object **obj, zend_str
return FAILURE;

default:
return zend_parse_arg_str_or_long_slow(zv, str, lval, 1 /* dummy */) ? SUCCESS : FAILURE;
return zend_parse_arg_long_slow(zv, lval, 1 /* dummy */) ? SUCCESS : FAILURE;
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions ext/bcmath/tests/gh15968.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-15968 BCMath\Number operators may typecast operand
--EXTENSIONS--
bcmath
--FILE--
<?php
class MyString {
function __toString() {
return "2";
}
}

$a = new BCMath\Number("1");
$b = new MyString();
try {
var_dump($a + $b);
} catch (Error $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Unsupported operand types: BcMath\Number + MyString
Loading