From 3cebc983a21a753699ae4bc019ee4a517e8f84a7 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Tue, 8 Mar 2022 22:25:48 +0100 Subject: [PATCH] rbutil: Fix a crash for devices without bootloader file. Don't try to get a bootloader filename from an empty list. This happens if the device doesn't have a bootloader file on disk. Change-Id: Idd4c265e7ae298913c5feefb3963120867a0e858 --- utils/rbutilqt/base/bootloaderinstallbase.cpp | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/utils/rbutilqt/base/bootloaderinstallbase.cpp b/utils/rbutilqt/base/bootloaderinstallbase.cpp index 096c601b91..c07d87bf36 100644 --- a/utils/rbutilqt/base/bootloaderinstallbase.cpp +++ b/utils/rbutilqt/base/bootloaderinstallbase.cpp @@ -116,19 +116,24 @@ void BootloaderInstallBase::progressAborted(void) bool BootloaderInstallBase::backup(QString to) { LOG_INFO() << "Backing up bootloader file"; - QDir targetDir("."); - emit logItem(tr("Creating backup of original firmware file."), LOGINFO); - if(!targetDir.mkpath(to)) { - emit logItem(tr("Creating backup folder failed"), LOGERROR); - return false; + if(!m_blfile.isEmpty()) { + QDir targetDir("."); + emit logItem(tr("Creating backup of original firmware file."), LOGINFO); + if(!targetDir.mkpath(to)) { + emit logItem(tr("Creating backup folder failed"), LOGERROR); + return false; + } + QString tofile = to + "/" + QFileInfo(m_blfile).fileName(); + LOG_INFO() << "trying to backup" << m_blfile << "to" << tofile; + if(!QFile::copy(Utils::resolvePathCase(m_blfile), tofile)) { + emit logItem(tr("Creating backup copy failed."), LOGERROR); + return false; + } + emit logItem(tr("Backup created."), LOGOK); } - QString tofile = to + "/" + QFileInfo(m_blfile).fileName(); - LOG_INFO() << "trying to backup" << m_blfile << "to" << tofile; - if(!QFile::copy(Utils::resolvePathCase(m_blfile), tofile)) { - emit logItem(tr("Creating backup copy failed."), LOGERROR); - return false; + else { + LOG_INFO() << "Bootloader backup not supported for current device."; } - emit logItem(tr("Backup created."), LOGOK); return true; } @@ -215,9 +220,6 @@ void BootloaderInstallBase::setBlFile(QStringList sl) m_blfile = sl.at(a); } } - if(m_blfile.isEmpty()) { - m_blfile = sl.at(0); - } }