Skip to content

Commit 7cbf4bd

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Add FPM test for php_admin_value doc_root usage Fix for bug in file handling refactor.
2 parents ae5498c + 435a5ac commit 7cbf4bd

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

main/fopen_wrappers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
402402
IS_ABSOLUTE_PATH(PG(doc_root), length)) {
403403
size_t path_len = strlen(path_info);
404404
filename = zend_string_alloc(length + path_len + 2, 0);
405-
memcpy(filename, PG(doc_root), length);
405+
memcpy(ZSTR_VAL(filename), PG(doc_root), length);
406406
if (!IS_SLASH(ZSTR_VAL(filename)[length - 1])) { /* length is never 0 */
407407
ZSTR_VAL(filename)[length++] = PHP_DIR_SEPARATOR;
408408
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
FPM: php_admin_value doc_root usage
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$docRoot = __DIR__ . '/';
11+
12+
$cfg = <<<EOT
13+
[global]
14+
error_log = {{FILE:LOG}}
15+
[unconfined]
16+
listen = {{ADDR}}
17+
pm = dynamic
18+
pm.max_children = 5
19+
pm.start_servers = 1
20+
pm.min_spare_servers = 1
21+
pm.max_spare_servers = 3
22+
php_admin_value[doc_root] = $docRoot
23+
EOT;
24+
25+
$code = <<<EOT
26+
<?php
27+
echo "OK";
28+
EOT;
29+
30+
$tester = new FPM\Tester($cfg, $code);
31+
$sourceFile = $tester->makeSourceFile();
32+
$tester->start();
33+
$tester->expectLogStartNotices();
34+
$tester->request(uri: basename($sourceFile), scriptFilename: $sourceFile)->expectBody('OK');
35+
$tester->terminate();
36+
$tester->close();
37+
38+
?>
39+
Done
40+
--EXPECT--
41+
Done
42+
--CLEAN--
43+
<?php
44+
require_once "tester.inc";
45+
FPM\Tester::clean();
46+
?>

sapi/fpm/tests/tester.inc

+8-8
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,14 @@ class Tester
527527
* @param string $query
528528
* @param array $headers
529529
* @param string|null $uri
530-
* @param string|null $address
531-
* @param string|null $successMessage
532-
* @param string|null $errorMessage
533-
* @param bool $connKeepAlive
530+
* @param string|null $scriptFilename
534531
* @return array
535532
*/
536533
private function getRequestParams(
537534
string $query = '',
538535
array $headers = [],
539-
string $uri = null
536+
string $uri = null,
537+
string $scriptFilename = null
540538
) {
541539
if (is_null($uri)) {
542540
$uri = $this->makeSourceFile();
@@ -546,7 +544,7 @@ class Tester
546544
[
547545
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
548546
'REQUEST_METHOD' => 'GET',
549-
'SCRIPT_FILENAME' => $uri,
547+
'SCRIPT_FILENAME' => $scriptFilename ?: $uri,
550548
'SCRIPT_NAME' => $uri,
551549
'QUERY_STRING' => $query,
552550
'REQUEST_URI' => $uri . ($query ? '?'.$query : ""),
@@ -580,6 +578,7 @@ class Tester
580578
* @param string|null $successMessage
581579
* @param string|null $errorMessage
582580
* @param bool $connKeepAlive
581+
* @param string|null $scriptFilename = null
583582
* @return Response
584583
*/
585584
public function request(
@@ -589,13 +588,14 @@ class Tester
589588
string $address = null,
590589
string $successMessage = null,
591590
string $errorMessage = null,
592-
bool $connKeepAlive = false
591+
bool $connKeepAlive = false,
592+
string $scriptFilename = null
593593
) {
594594
if ($this->hasError()) {
595595
return new Response(null, true);
596596
}
597597

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

600600
try {
601601
$this->response = new Response(

0 commit comments

Comments
 (0)