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
4 changes: 2 additions & 2 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,9 +1285,9 @@ static void init_request_info(fcgi_request *request)
*/
size_t slen = len - strlen(pt);
size_t pilen = env_path_info ? strlen(env_path_info) : 0;
char *path_info = env_path_info ? env_path_info + pilen - slen : NULL;
char *path_info = (env_path_info && pilen > slen) ? env_path_info + pilen - slen : NULL;

if (orig_path_info != path_info) {
if (path_info != NULL && orig_path_info != path_info) {
if (orig_path_info) {
char old;

Expand Down
37 changes: 37 additions & 0 deletions sapi/cgi/tests/fix_pathinfo_underflow.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
cgi fix_pathinfo with PATH_INFO shorter than the stripped suffix
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php

include "include.inc";

$php = get_cgi_path();
reset_env_vars();

$d = __DIR__ . '/fix_pathinfo_underflow';
@mkdir($d);
$f = $d . '/info.php';
file_put_contents($f, '<?php echo "PI=[", $_SERVER["PATH_INFO"] ?? "unset", "]", "\n"; ');

putenv("REDIRECT_STATUS=1");
putenv("SCRIPT_FILENAME=" . $f . "/" . str_repeat("a", 300));
putenv("PATH_INFO=/");
putenv("SCRIPT_NAME=/info.php");
putenv("REQUEST_METHOD=GET");
putenv("QUERY_STRING=");

echo `$php -n -d cgi.fix_pathinfo=1 $f`;

echo "Done\n";

@unlink($f);
@rmdir($d);
Comment on lines +29 to +30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
@unlink($f);
@rmdir($d);
?>
--CLEAN--
<?php
$d = __DIR__ . '/fix_pathinfo_underflow';
@unlink($d . '/info.php');
@rmdir($d);

?>
--EXPECTF--
X-Powered-By: PHP/%s
Content-type: text/html%r; charset=.*|%r

PI=[/]
Done
Loading