Skip to content

ext/curl: Fix CURLOPT_PREREQFUNCTION to not continue on error conditions#16790

Open
Ayesh wants to merge 1 commit into
php:PHP-8.4from
Ayesh:curl-prereq-earlyreturn-fix
Open

ext/curl: Fix CURLOPT_PREREQFUNCTION to not continue on error conditions#16790
Ayesh wants to merge 1 commit into
php:PHP-8.4from
Ayesh:curl-prereq-earlyreturn-fix

Conversation

@Ayesh

@Ayesh Ayesh commented Nov 14, 2024

Copy link
Copy Markdown
Member

This is a follow-up to GH-13255.

When the CURLOPT_PREREQFUNCTION callback does not return any value or return an invalid value, we throw a ValueError or a TypeError exception. However, it does not prevent the Curl request from going forward because our default return value is CURL_PREREQFUNC_OK.

This changes the default value to CURL_PREREQFUNC_ABORT.

…tions

This is a follow-up to phpGH-13255.

When the `CURLOPT_PREREQFUNCTION` callback does not return any value
or return an invalid value, we throw a `ValueError` or a `TypeError`
exception. However, it does not prevent the Curl request from going
forward because our default return value is `CURL_PREREQFUNC_OK`.

This changes the default value to `CURL_PREREQFUNC_ABORT`.
@cmb69

cmb69 commented Nov 14, 2024

Copy link
Copy Markdown
Member

Thank you! Looks good to me; can we test this?

Somewhat related: #16513.

@Sjord

Sjord commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Test:

--TEST--
CURLOPT_PREREQFUNCTION aborts transfer when callback throws
--EXTENSIONS--
curl
--SKIPIF--
<?php
if (!defined('CURLOPT_PREREQFUNCTION')) {
    die('skip CURLOPT_PREREQFUNCTION not available');
}
?>
--FILE--
<?php

include 'server.inc';
$host = curl_cli_server_start();
$ch = curl_init("{$host}/get.inc");

curl_setopt($ch, CURLOPT_PREREQFUNCTION,
    function (): int {
        throw new Exception('prereq failure');
    }
);

try {
    curl_exec($ch);
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}

var_dump(curl_errno($ch) === CURLE_ABORTED_BY_CALLBACK);

?>
--EXPECTF--
prereq failure
bool(true)

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.

3 participants