1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 16:26:59 +02:00

Add an additional check to WireDatabaseBackup so that a non-readable DB file doesn't cause a fatal exception

This commit is contained in:
Ryan Cramer
2023-05-05 08:53:15 -04:00
parent 6661f0490a
commit 013f9ebade

View File

@@ -49,7 +49,7 @@
* ~~~~~ * ~~~~~
* #pw-body * #pw-body
* *
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* *
@@ -534,7 +534,13 @@ class WireDatabaseBackup {
$filename = $this->sanitizeFilename($filename); $filename = $this->sanitizeFilename($filename);
if(!file_exists($filename)) return array(); if(!file_exists($filename)) return array();
$fp = fopen($filename, "r+"); $fp = fopen($filename, 'r');
if($fp === false) {
$this->error('Unable to open file for reading: ' . basename($filename));
return array();
}
$line = fgets($fp); $line = fgets($fp);
if(strpos($line, self::fileHeader) === 0 || strpos($line, "# " . self::fileHeader) === 0) { if(strpos($line, self::fileHeader) === 0 || strpos($line, "# " . self::fileHeader) === 0) {
$pos = strpos($line, '{'); $pos = strpos($line, '{');