From 5a8847f76cca9ad180c01ba23b95a9d7f085f0ae Mon Sep 17 00:00:00 2001 From: jlbprof Date: Tue, 16 Nov 2021 09:03:01 -0600 Subject: [PATCH 1/2] Fix for bug in file handling refactor. While testing the cPanel usage of PHP-FPM, we stumbled on this bug. Without the fix, the zend_string is corrupted and getting odd filenames When using FPM we kept getting "No input file specified". I work for cPanel and we use PHP extensively. --- main/fopen_wrappers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 59c20c82a5faf..f6ce26e104bee 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -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; } From 195624cb6f467cbec281f5bd63c4c041c6121af4 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sat, 20 Nov 2021 22:43:44 +0000 Subject: [PATCH 2/2] Add FPM test for php_admin_value doc_root usage --- sapi/fpm/tests/php-admin-doc-root.phpt | 46 ++++++++++++++++++++++++++ sapi/fpm/tests/tester.inc | 16 ++++----- 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 sapi/fpm/tests/php-admin-doc-root.phpt diff --git a/sapi/fpm/tests/php-admin-doc-root.phpt b/sapi/fpm/tests/php-admin-doc-root.phpt new file mode 100644 index 0000000000000..a078c3aa25267 --- /dev/null +++ b/sapi/fpm/tests/php-admin-doc-root.phpt @@ -0,0 +1,46 @@ +--TEST-- +FPM: php_admin_value doc_root usage +--SKIPIF-- + +--FILE-- +makeSourceFile(); +$tester->start(); +$tester->expectLogStartNotices(); +$tester->request(uri: basename($sourceFile), scriptFilename: $sourceFile)->expectBody('OK'); +$tester->terminate(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- + diff --git a/sapi/fpm/tests/tester.inc b/sapi/fpm/tests/tester.inc index cd043072ba031..c3c00cdc95874 100644 --- a/sapi/fpm/tests/tester.inc +++ b/sapi/fpm/tests/tester.inc @@ -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 $scritpFilename * @return array */ private function getRequestParams( string $query = '', array $headers = [], - string $uri = null + string $uri = null, + string $scritpFilename = null ) { if (is_null($uri)) { $uri = $this->makeSourceFile(); @@ -546,7 +544,7 @@ class Tester [ 'GATEWAY_INTERFACE' => 'FastCGI/1.0', 'REQUEST_METHOD' => 'GET', - 'SCRIPT_FILENAME' => $uri, + 'SCRIPT_FILENAME' => $scritpFilename ?: $uri, 'SCRIPT_NAME' => $uri, 'QUERY_STRING' => $query, 'REQUEST_URI' => $uri . ($query ? '?'.$query : ""), @@ -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( @@ -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(