From a87f45a6ca51377550cb638878c5ae3d38d02632 Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 13 Feb 2023 14:55:20 +0100 Subject: [PATCH 1/3] add a disk_free_space check before writing config Signed-off-by: Simon L --- lib/private/Config.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/private/Config.php b/lib/private/Config.php index 0e3a9b22a7710..af6b71e3df3b2 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -277,6 +277,12 @@ private function writeData() { 'This can usually be fixed by giving the webserver write access to the config directory.'); } + // Never write file back if disk space should be low (less than 100 KiB) + $df = disk_free_space($this->configDir); + if ($df !== false && (int)$df < 102400) { + throw new \Exception($this->configDir . " does not have enough space for writing the config file! Not writing it back!"); + } + // Try to acquire a file lock if (!flock($filePointer, LOCK_EX)) { throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath)); From b3fb30b8b0ebf42996a3a5e4b2a0e22e85614c38 Mon Sep 17 00:00:00 2001 From: Simon L Date: Wed, 15 Feb 2023 13:43:54 +0100 Subject: [PATCH 2/3] address review by Joas Signed-off-by: Simon L --- lib/private/Config.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/private/Config.php b/lib/private/Config.php index af6b71e3df3b2..039f81a75de12 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -277,9 +277,10 @@ private function writeData() { 'This can usually be fixed by giving the webserver write access to the config directory.'); } - // Never write file back if disk space should be low (less than 100 KiB) + // Never write file back if disk space should be too low $df = disk_free_space($this->configDir); - if ($df !== false && (int)$df < 102400) { + $size = strlen($content) + 10240; + if ($df !== false && (int)$df < $size) { throw new \Exception($this->configDir . " does not have enough space for writing the config file! Not writing it back!"); } From b3a64a91211dfb1fbda0c13612fabd587e2ed283 Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 20 Feb 2023 10:15:20 +0100 Subject: [PATCH 3/3] fix it for 32-bit Signed-off-by: Simon L --- lib/private/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Config.php b/lib/private/Config.php index 039f81a75de12..7e9684dda91c0 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -280,7 +280,7 @@ private function writeData() { // Never write file back if disk space should be too low $df = disk_free_space($this->configDir); $size = strlen($content) + 10240; - if ($df !== false && (int)$df < $size) { + if ($df !== false && $df < (float)$size) { throw new \Exception($this->configDir . " does not have enough space for writing the config file! Not writing it back!"); }