Skip to content

Fixed GH-15547: curl_multi_wait expects a signed int for timeout. #15548

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
8 changes: 7 additions & 1 deletion ext/curl/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ PHP_FUNCTION(curl_multi_select)

mh = Z_CURL_MULTI_P(z_mh);

error = curl_multi_wait(mh->multi, NULL, 0, (unsigned long) (timeout * 1000.0), &numfds);
if (!(timeout >= 0.0 && timeout <= ((double)INT_MAX / 1000.0))) {
php_error_docref(NULL, E_WARNING, "timeout must be between 0 and %d", (int)ceilf((double)INT_MAX / 1000));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the ceilf() is still not quite correct. Maybe we should actually output a float value? Or maybe leave as is, and call it a day. It's quite unlikely that a user specifies a timeout of almost a month.

SAVE_CURLM_ERROR(mh, CURLM_BAD_FUNCTION_ARGUMENT);
RETURN_LONG(-1);
}

error = curl_multi_wait(mh->multi, NULL, 0, (int) (timeout * 1000.0), &numfds);
if (CURLM_OK != error) {
SAVE_CURLM_ERROR(mh, error);
RETURN_LONG(-1);
Expand Down
29 changes: 29 additions & 0 deletions ext/curl/tests/gh15547.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-15547 - curl_multi_select overflow on timeout argument
--EXTENSIONS--
curl
--FILE--
<?php

$mh = curl_multi_init();
var_dump(curl_multi_select($mh, -2500000));
var_dump(curl_multi_strerror(curl_multi_errno($mh)));
curl_multi_close($mh);
$mh = curl_multi_init();
var_dump(curl_multi_select($mh, 2500000));
var_dump(curl_multi_strerror(curl_multi_errno($mh)));
curl_multi_close($mh);
$mh = curl_multi_init();
var_dump(curl_multi_select($mh, 1000000));
var_dump(curl_multi_strerror(curl_multi_errno($mh)));
?>
--EXPECTF--
Warning: curl_multi_select(): timeout must be between 0 and %d in %s on line %d
int(-1)
string(43) "A libcurl function was given a bad argument"

Warning: curl_multi_select(): timeout must be between 0 and %d in %s on line %d
int(-1)
string(43) "A libcurl function was given a bad argument"
int(0)
string(8) "No error"
Loading