diff --git a/ext/curl/interface.c b/ext/curl/interface.c index b8c6ce7dde3e..79ec1b011837 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1906,8 +1906,6 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue break; /* String options */ - case CURLOPT_CAINFO: - case CURLOPT_CAPATH: case CURLOPT_COOKIE: case CURLOPT_EGDSOCKET: case CURLOPT_INTERFACE: @@ -2002,6 +2000,8 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue } /* Curl nullable string options */ + case CURLOPT_CAINFO: + case CURLOPT_CAPATH: case CURLOPT_CUSTOMREQUEST: case CURLOPT_FTPPORT: case CURLOPT_RANGE: diff --git a/ext/curl/tests/gh25727.phpt b/ext/curl/tests/gh25727.phpt new file mode 100644 index 000000000000..d1da2f92cf77 --- /dev/null +++ b/ext/curl/tests/gh25727.phpt @@ -0,0 +1,103 @@ +--TEST-- +GH-25727 (CURLOPT_CAINFO and CURLOPT_CAPATH do not accept null) +--EXTENSIONS-- +curl +--SKIPIF-- + 0) die("skip couldn't locate openssl binary"); +if (PHP_OS_FAMILY === 'Windows') die('skip not for Windows'); +if (PHP_OS_FAMILY === 'Darwin') die('skip Fails intermittently on macOS'); +if (PHP_OS === 'FreeBSD') die('skip proc_open seems to be stuck on FreeBSD'); +if (!str_contains(curl_version()['ssl_version'], 'OpenSSL')) { + die('skip CURLOPT_CAPATH with a hashed directory needs libcurl built with OpenSSL'); +} +?> +--FILE-- +.0 */ +$caPath = __DIR__ . DIRECTORY_SEPARATOR . 'gh25727_capath'; +$hash = exec("openssl x509 -noout -subject_hash -in $serverCertPath"); +@mkdir($caPath); +copy($serverCertPath, $caPath . DIRECTORY_SEPARATOR . $hash . '.0'); + +$port = 14431; + +$cmd = "openssl s_server -key $serverKeyPath -cert $serverCertPath -accept $port -www"; +$process = proc_open($cmd, [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes); + +if ($process === false) { + die('failed to start server'); +} +try { + // Wait until OpenSSL is actually listening before making the first request. + $ready = false; + for ($i = 0; $i < 100; $i++) { + $connection = @stream_socket_client("tcp://127.0.0.1:$port", $errno, $errstr, 0.05); + if ($connection !== false) { + fclose($connection); + $ready = true; + break; + } + if (!proc_get_status($process)['running']) { + break; + } + usleep(50000); + } + if (!$ready) { + stream_set_blocking($pipes[2], false); + throw new RuntimeException('OpenSSL server did not start: ' . trim(stream_get_contents($pipes[2]))); + } + + echo "CAINFO disabled, certificate found in CAPATH\n"; + request($port, [CURLOPT_CAINFO => null, CURLOPT_CAPATH => $caPath]); + + echo "CAPATH disabled, certificate found in CAINFO\n"; + request($port, [CURLOPT_CAINFO => $serverCertPath, CURLOPT_CAPATH => null]); + + echo "CAINFO set and then disabled, CAPATH disabled\n"; + request($port, [CURLOPT_CAINFO => $serverCertPath], [CURLOPT_CAINFO => null, CURLOPT_CAPATH => null]); +} finally { + proc_terminate($process); + proc_close($process); +} + +?> +--CLEAN-- + +--EXPECT-- +CAINFO disabled, certificate found in CAPATH +bool(true) +bool(true) +int(0) +CAPATH disabled, certificate found in CAINFO +bool(true) +bool(true) +int(0) +CAINFO set and then disabled, CAPATH disabled +bool(true) +bool(true) +bool(false) +int(60)