Skip to content

Commit 808b1b1

Browse files
committed
Fix potential script termination when using unchecked variable
self::getReposArchives claims to return array but returns bool as well. All other calls of this function properly check if the result is array. In a case where false is returned, this code can throw a fatal error and cause stop of entire script execution wherever it is.
1 parent 10338e4 commit 808b1b1

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

server/lib/classes/backup.inc.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,22 +1197,26 @@ protected static function getAllArchives($backup_dir, $backup_mode, $password, $
11971197
case 'borg':
11981198
$repos_path = $backup_dir . '/' . $entry;
11991199
if (is_dir($repos_path) && strncmp('borg_', $entry, 5) === 0) {
1200-
$archivesJson = json_decode(implode("", self::getReposArchives($backup_mode, $repos_path, $password, 'json')), TRUE);
1201-
foreach ($archivesJson['archives'] as $archive) {
1202-
if (is_null($prefix_list)) { //fallback if no prefix_list
1203-
$archives[] = [
1204-
'repos' => $entry,
1205-
'archive' => $archive['name'],
1206-
'created_at' => strtotime($archive['time']),
1207-
];
1208-
} else {
1209-
foreach ($prefix_list as $prefix) {
1210-
if (substr($archive['name'], 0, strlen($prefix)) == $prefix) { //filter backup list of all if no prefix_list
1211-
$archives[] = [
1212-
'repos' => $entry,
1213-
'archive' => $archive['name'],
1214-
'created_at' => strtotime($archive['time']),
1215-
];
1200+
$repos_archives = self::getReposArchives($backup_mode, $repos_path, $password, 'json');
1201+
if(is_array($repos_archives))
1202+
{
1203+
$archivesJson = json_decode(implode("", $repos_archives), TRUE);
1204+
foreach ($archivesJson['archives'] as $archive) {
1205+
if (is_null($prefix_list)) { //fallback if no prefix_list
1206+
$archives[] = [
1207+
'repos' => $entry,
1208+
'archive' => $archive['name'],
1209+
'created_at' => strtotime($archive['time']),
1210+
];
1211+
} else {
1212+
foreach ($prefix_list as $prefix) {
1213+
if (substr($archive['name'], 0, strlen($prefix)) == $prefix) { //filter backup list of all if no prefix_list
1214+
$archives[] = [
1215+
'repos' => $entry,
1216+
'archive' => $archive['name'],
1217+
'created_at' => strtotime($archive['time']),
1218+
];
1219+
}
12161220
}
12171221
}
12181222
}

0 commit comments

Comments
 (0)