Skip to content

Commit

Permalink
Merge branch 'PHP-8.1'
Browse files Browse the repository at this point in the history
* PHP-8.1:
  Add FPM test for php_admin_value doc_root usage
  Fix for bug in file handling refactor.
  • Loading branch information
nikic committed Nov 23, 2021
2 parents ae5498c + 435a5ac commit 7cbf4bd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main/fopen_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
IS_ABSOLUTE_PATH(PG(doc_root), length)) {
size_t path_len = strlen(path_info);
filename = zend_string_alloc(length + path_len + 2, 0);
memcpy(filename, PG(doc_root), length);
memcpy(ZSTR_VAL(filename), PG(doc_root), length);
if (!IS_SLASH(ZSTR_VAL(filename)[length - 1])) { /* length is never 0 */
ZSTR_VAL(filename)[length++] = PHP_DIR_SEPARATOR;
}
Expand Down
46 changes: 46 additions & 0 deletions sapi/fpm/tests/php-admin-doc-root.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
FPM: php_admin_value doc_root usage
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php

require_once "tester.inc";

$docRoot = __DIR__ . '/';

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_admin_value[doc_root] = $docRoot
EOT;

$code = <<<EOT
<?php
echo "OK";
EOT;

$tester = new FPM\Tester($cfg, $code);
$sourceFile = $tester->makeSourceFile();
$tester->start();
$tester->expectLogStartNotices();
$tester->request(uri: basename($sourceFile), scriptFilename: $sourceFile)->expectBody('OK');
$tester->terminate();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
16 changes: 8 additions & 8 deletions sapi/fpm/tests/tester.inc
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,14 @@ class Tester
* @param string $query
* @param array $headers
* @param string|null $uri
* @param string|null $address
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param string|null $scriptFilename
* @return array
*/
private function getRequestParams(
string $query = '',
array $headers = [],
string $uri = null
string $uri = null,
string $scriptFilename = null
) {
if (is_null($uri)) {
$uri = $this->makeSourceFile();
Expand All @@ -546,7 +544,7 @@ class Tester
[
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
'REQUEST_METHOD' => 'GET',
'SCRIPT_FILENAME' => $uri,
'SCRIPT_FILENAME' => $scriptFilename ?: $uri,
'SCRIPT_NAME' => $uri,
'QUERY_STRING' => $query,
'REQUEST_URI' => $uri . ($query ? '?'.$query : ""),
Expand Down Expand Up @@ -580,6 +578,7 @@ class Tester
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param string|null $scriptFilename = null
* @return Response
*/
public function request(
Expand All @@ -589,13 +588,14 @@ class Tester
string $address = null,
string $successMessage = null,
string $errorMessage = null,
bool $connKeepAlive = false
bool $connKeepAlive = false,
string $scriptFilename = null
) {
if ($this->hasError()) {
return new Response(null, true);
}

$params = $this->getRequestParams($query, $headers, $uri);
$params = $this->getRequestParams($query, $headers, $uri, $scriptFilename);

try {
$this->response = new Response(
Expand Down

0 comments on commit 7cbf4bd

Please sign in to comment.