Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ PHP NEWS
. Fix OSS-Fuzz #588264417. (ndossche)
. Fixed bug GH-24701 (Use-after-free on typed trait constants during
opcache preload). (sanklamm, lazerg)
. Fixed NULL dereference at startup when the ini file found in the search
path has an absolute path exceeding MAXPATHLEN. (Jorg Sowa)

- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
Expand Down
9 changes: 6 additions & 3 deletions main/fopen_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,13 @@ static FILE *php_fopen_and_set_opened_path(const char *path, const char *mode, z
if (fp && opened_path) {
//TODO :avoid reallocation
char *tmp = expand_filepath_with_mode(path, NULL, NULL, 0, CWD_EXPAND);
if (tmp) {
*opened_path = zend_string_init(tmp, strlen(tmp), 0);
efree(tmp);
if (!tmp) {
/* Reject the file, like ZTS where VCWD_FOPEN() already fails */
fclose(fp);
return NULL;
}
*opened_path = zend_string_init(tmp, strlen(tmp), 0);
efree(tmp);
}
return fp;
}
Expand Down
29 changes: 29 additions & 0 deletions sapi/cli/tests/ini_search_path_sapi_unresolvable.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
php-cli.ini in search path is skipped when its absolute path exceeds MAXPATHLEN
--SKIPIF--
<?php
include "skipif.inc";
if (PHP_OS_FAMILY === "Windows") die("skip not for Windows");
?>
--FILE--
<?php
$dir = __DIR__ . "/ini_search_path_sapi_unresolvable";
@mkdir($dir);
file_put_contents("$dir/php-cli.ini", "foo=bar\n");

$relative = str_repeat("./", intdiv(PHP_MAXPATHLEN - strlen($dir), 2));
$proc = proc_open(
[getenv("TEST_PHP_EXECUTABLE"), "-c", $relative . PATH_SEPARATOR . ".", "-r", 'var_dump(get_cfg_var("foo"));'],
[1 => ["pipe", "w"]],
$pipes,
$dir
);
echo stream_get_contents($pipes[1]);
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/ini_search_path_sapi_unresolvable/php-cli.ini");
@rmdir(__DIR__ . "/ini_search_path_sapi_unresolvable");
?>
--EXPECT--
string(3) "bar"
29 changes: 29 additions & 0 deletions sapi/cli/tests/ini_search_path_unresolvable.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
php.ini in search path is skipped when its absolute path exceeds MAXPATHLEN
--SKIPIF--
<?php
include "skipif.inc";
if (PHP_OS_FAMILY === "Windows") die("skip not for Windows");
?>
--FILE--
<?php
$dir = __DIR__ . "/ini_search_path_unresolvable";
@mkdir($dir);
file_put_contents("$dir/php.ini", "foo=bar\n");

$relative = str_repeat("./", intdiv(PHP_MAXPATHLEN - strlen($dir), 2));
$proc = proc_open(
[getenv("TEST_PHP_EXECUTABLE"), "-c", $relative . PATH_SEPARATOR . ".", "-r", 'var_dump(get_cfg_var("foo"));'],
[1 => ["pipe", "w"]],
$pipes,
$dir
);
echo stream_get_contents($pipes[1]);
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/ini_search_path_unresolvable/php.ini");
@rmdir(__DIR__ . "/ini_search_path_unresolvable");
?>
--EXPECT--
string(3) "bar"
Loading