Skip to content

Commit c5b258f

Browse files
Fix GH-15968: Avoid converting objects to strings in operator calculations. (#16021)
1 parent 654b787 commit c5b258f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. bcpow() performance improvement. (Jorg Sowa)
77
. ext/bcmath: Check for scale overflow. (SakiTakamachi)
88
. [RFC] ext/bcmath: Added bcdivmod. (SakiTakamachi)
9+
. Fix GH-15968 (Avoid converting objects to strings in operator calculations).
10+
(SakiTakamachi)
911

1012
- Curl:
1113
. Added CURLOPT_DEBUGFUNCTION as a Curl option. (Ayesh Karunaratne)

ext/bcmath/bcmath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ static zend_result bcmath_number_parse_num(zval *zv, zend_object **obj, zend_str
11781178
return FAILURE;
11791179

11801180
default:
1181-
return zend_parse_arg_str_or_long_slow(zv, str, lval, 1 /* dummy */) ? SUCCESS : FAILURE;
1181+
return zend_parse_arg_long_slow(zv, lval, 1 /* dummy */) ? SUCCESS : FAILURE;
11821182
}
11831183
}
11841184
}

ext/bcmath/tests/gh15968.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-15968 BCMath\Number operators may typecast operand
3+
--EXTENSIONS--
4+
bcmath
5+
--FILE--
6+
<?php
7+
class MyString {
8+
function __toString() {
9+
return "2";
10+
}
11+
}
12+
13+
$a = new BCMath\Number("1");
14+
$b = new MyString();
15+
try {
16+
var_dump($a + $b);
17+
} catch (Error $e) {
18+
echo $e->getMessage();
19+
}
20+
?>
21+
--EXPECT--
22+
Unsupported operand types: BcMath\Number + MyString

0 commit comments

Comments
 (0)