1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

RestoreManager: Validate all elements in session file

Session file can be corrupted or have data from unsupported version
inside the file.
This commit is contained in:
David Rosca 2018-02-03 10:53:07 +01:00
parent e6b220a87a
commit 6985a8567a
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 15 additions and 21 deletions

View File

@ -122,6 +122,11 @@ BrowserWindow::SavedWindow::SavedWindow(BrowserWindow *window)
bool BrowserWindow::SavedWindow::isValid() const
{
for (const WebTab::SavedTab &tab : qAsConst(tabs)) {
if (!tab.isValid()) {
return false;
}
}
return currentTab > -1;
}

View File

@ -26,12 +26,19 @@ static const int restoreDataVersion = 2;
bool RestoreData::isValid() const
{
for (const BrowserWindow::SavedWindow &window : qAsConst(windows)) {
if (!window.isValid()) {
return false;
}
}
return !windows.isEmpty();
}
void RestoreData::clear()
{
windows.clear();
crashedSession.clear();
closedWindows.clear();
}
QDataStream &operator<<(QDataStream &stream, const RestoreData &data)
@ -155,27 +162,9 @@ static void loadVersion3(QDataStream &stream, RestoreData &data)
// static
bool RestoreManager::validateFile(const QString &file)
{
if (!QFile::exists(file)) {
return false;
}
QFile recoveryFile(file);
if (!recoveryFile.open(QIODevice::ReadOnly)) {
return false;
}
QDataStream stream(&recoveryFile);
int version;
stream >> version;
if (version == Qz::sessionVersion || version == 0x0003 || version == (0x0003 | 0x050000)) {
int windowCount;
stream >> windowCount;
return windowCount > 0;
}
return false;
RestoreData data;
createFromFile(file, data);
return data.isValid();
}
// static