Skip to content

Fix curl_multi_errno() returning a stale error code - #25559

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/curl-multi-errno-stale-PHP-8.4
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/curl-multi-errno-stale-PHP-8.4

Conversation

@lacatoire

Copy link
Copy Markdown
Member

curl_multi_select() only saved the multi-stack error code on failure, so a success left a previous error in place, unlike the other call sites. The CURLMOPT_PUSHFUNCTION branch of curl_multi_setopt() also returned early on an invalid callback without saving any error. Both now go through SAVE_CURLM_ERROR() whatever the outcome.

To reproduce:

$mh = curl_multi_init();
$ch = curl_init();
curl_multi_add_handle($mh, $ch);
curl_multi_add_handle($mh, $ch); // CURLM_ADDED_ALREADY
echo curl_multi_errno($mh), "\n";
curl_multi_select($mh, 0.01);
echo curl_multi_errno($mh), "\n";
curl_multi_add_handle($mh, $ch);
echo curl_multi_errno($mh), "\n";
try {
    curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, "not a callable");
} catch (TypeError) {
}
echo curl_multi_errno($mh), "\n";

Before (8.4.26, 8.5.12): 7, 7, 7, 7.

After: 7, 0, 7, 10.

curl_multi_select() only called SAVE_CURLM_ERROR() on failure, leaving
a previous error code in place after a successful call, unlike the
other multi-stack functions which reset it unconditionally. The
CURLMOPT_PUSHFUNCTION branch of curl_multi_setopt() also returned
early on an invalid callback before saving any error, silently
keeping the previous error code even though this call failed too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant