From 3b622bc0055b25cde4ee8b997764caaf4c82f53b Mon Sep 17 00:00:00 2001 From: Derky Date: Sat, 23 Sep 2023 16:38:32 +0200 Subject: [PATCH 1/4] [ticket/17189] Check folder permissions before writing PHPBB3-17189 --- phpBB/install/startup.php | 2 +- phpBB/phpbb/cache/driver/file.php | 4 ++-- phpBB/phpbb/filesystem/filesystem.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index 0aaa9a648f..0180996a19 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -161,7 +161,7 @@ function installer_shutdown_function($display_errors) $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer'); $filesystem = new \phpbb\filesystem\filesystem(); - if (strpos($error['file'], $filesystem->realpath($cache->cache_dir)) !== false) + if (strpos($error['file'], $filesystem->realpath($cache->cache_dir)) !== false && is_writable($cache->cache_dir)) { $file_age = @filemtime($error['file']); diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 36150d0589..4190f65342 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -37,9 +37,9 @@ class file extends \phpbb\cache\driver\base $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir'); $this->filesystem = new \phpbb\filesystem\filesystem(); - if (!is_dir($this->cache_dir)) + if ($this->filesystem->is_writable($this->cache_dir . '/../') && !is_dir($this->cache_dir)) { - @mkdir($this->cache_dir, 0777, true); + mkdir($this->cache_dir, 0777, true); } } diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index fc7cbdf27d..3e60a6f2fb 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -398,13 +398,13 @@ class filesystem implements filesystem_interface $file_gid = @filegroup($file); // Change owner - if ($file_uid !== $this->chmod_info['common_owner']) + if (is_writable($file) && $file_uid !== $this->chmod_info['common_owner']) { $this->chown($file, $this->chmod_info['common_owner'], $recursive); } // Change group - if ($file_gid !== $this->chmod_info['common_group']) + if (is_writable($file) && $file_gid !== $this->chmod_info['common_group']) { $this->chgrp($file, $this->chmod_info['common_group'], $recursive); } From a78eb6fb42312c8c8503e8d5f40640288d8b730a Mon Sep 17 00:00:00 2001 From: Derky Date: Sat, 23 Sep 2023 16:43:41 +0200 Subject: [PATCH 2/4] [ticket/17189] Show file names that couldn't be modified by installer PHPBB3-17189 --- .../phpbb/install/module/requirements/task/check_filesystem.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/phpbb/install/module/requirements/task/check_filesystem.php b/phpBB/phpbb/install/module/requirements/task/check_filesystem.php index 868af39433..f7ff019422 100644 --- a/phpBB/phpbb/install/module/requirements/task/check_filesystem.php +++ b/phpBB/phpbb/install/module/requirements/task/check_filesystem.php @@ -217,6 +217,7 @@ class check_filesystem extends \phpbb\install\task_base catch (\phpbb\filesystem\exception\filesystem_exception $e) { // Do nothing + $this->response->add_warning_message($e->getMessage(), $e->get_filename()); } } @@ -232,6 +233,7 @@ class check_filesystem extends \phpbb\install\task_base } catch (\phpbb\filesystem\exception\filesystem_exception $e) { + $this->response->add_warning_message($e->getMessage(), $e->get_filename()); // Do nothing } } From 6b6c710706779d5fb4fcd86b62b2b3218f9ae3fb Mon Sep 17 00:00:00 2001 From: Derky Date: Sun, 24 Sep 2023 13:43:42 +0200 Subject: [PATCH 3/4] [ticket/17189] Append slash after installer cache path PHPBB3-17189 --- phpBB/install/startup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index 0180996a19..0f2b1a60a0 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -159,7 +159,7 @@ function installer_shutdown_function($display_errors) installer_class_loader($phpbb_root_path, $phpEx); $supported_error_levels = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED; - $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer'); + $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer/'); $filesystem = new \phpbb\filesystem\filesystem(); if (strpos($error['file'], $filesystem->realpath($cache->cache_dir)) !== false && is_writable($cache->cache_dir)) { From 91b3627236220f1ea0607c7005da20bf074cd095 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 2 Oct 2023 21:45:31 +0200 Subject: [PATCH 4/4] [ticket/17189] Check if different way of getting parent path works better PHPBB3-17189 --- phpBB/phpbb/cache/driver/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 4190f65342..a07b9a9701 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -37,7 +37,7 @@ class file extends \phpbb\cache\driver\base $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir'); $this->filesystem = new \phpbb\filesystem\filesystem(); - if ($this->filesystem->is_writable($this->cache_dir . '/../') && !is_dir($this->cache_dir)) + if ($this->filesystem->is_writable(dirname($this->cache_dir)) && !is_dir($this->cache_dir)) { mkdir($this->cache_dir, 0777, true); }