Skip to content

Commit 66042a4

Browse files
committed
ext/curl: Use try conversion functions in curl
1 parent 3254c4e commit 66042a4

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.7.0alpha1
44

5+
- Curl:
6+
. curl_multi_exec() now throws a TypeError when still_running is not an int.
7+
(arshidkv12)
8+
59
- FPM:
610
. Use recommended TYPE, HELP order for OpenMetrics metadata.
711
(Marcel Hernandez)

‎UPGRADING‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ PHP 8.7 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- Curl:
23+
. curl_multi_exec() now throws a TypeError when still_running is not an int.
24+
2225
- PDO:
2326
. PDOStatement::bindColumn() now throws a ValueError when the column name is
2427
not present in the result set. It previously reported the condition

‎ext/curl/multi.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,15 @@ PHP_FUNCTION(curl_multi_exec)
254254
_php_curl_verify_handlers(ch, /* reporterror */ true);
255255
}
256256
}
257+
258+
bool failed = false;
257259

258-
still_running = zval_get_long(z_still_running);
260+
still_running = zval_try_get_long(z_still_running, &failed);
261+
if (UNEXPECTED(failed)) {
262+
zend_argument_type_error(2, "must be of type int, %s given", zend_zval_value_name(z_still_running));
263+
RETURN_THROWS();
264+
}
265+
259266
error = curl_multi_perform(mh->multi, &still_running);
260267
ZEND_TRY_ASSIGN_REF_LONG(z_still_running, still_running);
261268

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
curl_multi_exec(): zval conversion for still_running
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
8+
$mh = curl_multi_init();
9+
10+
$values = [
11+
'1',
12+
'abc',
13+
1.5,
14+
true,
15+
false,
16+
null,
17+
[],
18+
new stdClass(),
19+
];
20+
21+
foreach ($values as $value) {
22+
$still_running = $value;
23+
24+
try {
25+
$result = curl_multi_exec($mh, $still_running);
26+
27+
var_dump($result);
28+
var_dump($still_running);
29+
} catch (Throwable $e) {
30+
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
31+
}
32+
}
33+
34+
curl_multi_close($mh);
35+
?>
36+
--EXPECTF--
37+
int(0)
38+
int(0)
39+
TypeError: curl_multi_exec(): Argument #2 ($still_running) must be of type int, string given
40+
41+
Deprecated: Implicit conversion from float 1.5 to int loses precision in %s on line %d
42+
int(0)
43+
int(0)
44+
int(0)
45+
int(0)
46+
int(0)
47+
int(0)
48+
int(0)
49+
int(0)
50+
TypeError: curl_multi_exec(): Argument #2 ($still_running) must be of type int, array given
51+
TypeError: curl_multi_exec(): Argument #2 ($still_running) must be of type int, stdClass given

0 commit comments

Comments
 (0)