From 9b6e5c6674e1dd8bf332a76ea1572fec5876f532 Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 13 Feb 2023 14:55:20 +0100 Subject: 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 ba3b8c6fe4d..53033d3a830 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -285,6 +285,12 @@ class Config { '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)); -- cgit v1.2.3 From 3757b345bc47adaeb3b25f1fb1cb5f8fade1676d Mon Sep 17 00:00:00 2001 From: Simon L Date: Wed, 15 Feb 2023 13:43:54 +0100 Subject: 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 53033d3a830..7308a3769df 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -285,9 +285,10 @@ class Config { '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!"); } -- cgit v1.2.3