mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-21 23:48:22 +08:00
Version 0.17.8
-fixed bugs found by first scan with Coverity Scan
This commit is contained in:
parent
706b0088e3
commit
1df4e4f9d8
@ -28,6 +28,8 @@ FfsEngine::FfsEngine(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
model = new TreeModel();
|
||||
oldPeiCoreEntryPoint = 0;
|
||||
newPeiCoreEntryPoint = 0;
|
||||
}
|
||||
|
||||
FfsEngine::~FfsEngine(void)
|
||||
@ -71,8 +73,6 @@ bool FfsEngine::hasIntersection(const UINT32 begin1, const UINT32 end1, const UI
|
||||
// Firmware image parsing
|
||||
UINT8 FfsEngine::parseImageFile(const QByteArray & buffer)
|
||||
{
|
||||
oldPeiCoreEntryPoint = 0;
|
||||
newPeiCoreEntryPoint = 0;
|
||||
UINT32 capsuleHeaderSize = 0;
|
||||
FLASH_DESCRIPTOR_HEADER* descriptorHeader = NULL;
|
||||
QModelIndex index;
|
||||
@ -828,7 +828,7 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
|
||||
|
||||
// Check file state
|
||||
// Determine file erase polarity
|
||||
bool fileErasePolarity = fileHeader->State | EFI_FILE_ERASE_POLARITY;
|
||||
bool fileErasePolarity = fileHeader->State & EFI_FILE_ERASE_POLARITY;
|
||||
|
||||
// Check file erase polarity to be the same as parent erase polarity
|
||||
if (erasePolarity != ERASE_POLARITY_UNKNOWN && (bool) erasePolarity != fileErasePolarity) {
|
||||
@ -1702,6 +1702,8 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
||||
if (ERR_SUCCESS != EfiDecompress(data, dataSize, decompressed, decompressedSize, scratch, scratchSize)) {
|
||||
if (algorithm)
|
||||
*algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
|
||||
delete[] decompressed;
|
||||
delete[] scratch;
|
||||
return ERR_STANDARD_DECOMPRESSION_FAILED;
|
||||
}
|
||||
else if (algorithm)
|
||||
@ -1712,10 +1714,8 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
||||
|
||||
decompressedData = QByteArray((const char*) decompressed, decompressedSize);
|
||||
|
||||
// Free allocated memory
|
||||
delete[] decompressed;
|
||||
delete[] scratch;
|
||||
|
||||
return ERR_SUCCESS;
|
||||
case EFI_CUSTOMIZED_COMPRESSION:
|
||||
// Get buffer sizes
|
||||
@ -1743,13 +1743,16 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
||||
data += shittySectionSize;
|
||||
|
||||
// Get info again
|
||||
if (ERR_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize))
|
||||
if (ERR_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) {
|
||||
delete[] decompressed;
|
||||
return ERR_CUSTOMIZED_DECOMPRESSION_FAILED;
|
||||
}
|
||||
|
||||
// Decompress section data again
|
||||
if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) {
|
||||
if (algorithm)
|
||||
*algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
|
||||
delete[] decompressed;
|
||||
return ERR_CUSTOMIZED_DECOMPRESSION_FAILED;
|
||||
}
|
||||
else {
|
||||
@ -1764,9 +1767,7 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
||||
decompressedData = QByteArray((const char*) decompressed, decompressedSize);
|
||||
}
|
||||
|
||||
// Free memory
|
||||
delete[] decompressed;
|
||||
|
||||
return ERR_SUCCESS;
|
||||
default:
|
||||
msg(tr("decompress: Unknown compression type (%1)").arg(compressionType));
|
||||
@ -1793,8 +1794,10 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
|
||||
if (EfiCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
|
||||
return ERR_STANDARD_COMPRESSION_FAILED;
|
||||
compressed = new UINT8[compressedSize];
|
||||
if (EfiCompress((UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
|
||||
if (EfiCompress((UINT8*)data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) {
|
||||
delete[] compressed;
|
||||
return ERR_STANDARD_COMPRESSION_FAILED;
|
||||
}
|
||||
compressedData = QByteArray((const char*) compressed, compressedSize);
|
||||
delete[] compressed;
|
||||
return ERR_SUCCESS;
|
||||
@ -1805,8 +1808,10 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
|
||||
if (TianoCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
|
||||
return ERR_STANDARD_COMPRESSION_FAILED;
|
||||
compressed = new UINT8[compressedSize];
|
||||
if (TianoCompress((UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
|
||||
if (TianoCompress((UINT8*)data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) {
|
||||
delete[] compressed;
|
||||
return ERR_STANDARD_COMPRESSION_FAILED;
|
||||
}
|
||||
compressedData = QByteArray((const char*) compressed, compressedSize);
|
||||
delete[] compressed;
|
||||
return ERR_SUCCESS;
|
||||
@ -1817,8 +1822,10 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
|
||||
if (LzmaCompress((const UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
|
||||
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
|
||||
compressed = new UINT8[compressedSize];
|
||||
if (LzmaCompress((const UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
|
||||
if (LzmaCompress((const UINT8*)data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) {
|
||||
delete[] compressed;
|
||||
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
|
||||
}
|
||||
compressedData = QByteArray((const char*) compressed, compressedSize);
|
||||
delete[] compressed;
|
||||
return ERR_SUCCESS;
|
||||
@ -1834,8 +1841,10 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
|
||||
if (LzmaCompress((UINT8*) newData.constData(), newData.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
|
||||
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
|
||||
compressed = new UINT8[compressedSize];
|
||||
if (LzmaCompress((UINT8*) newData.constData(), newData.size(), compressed, &compressedSize) != ERR_SUCCESS)
|
||||
if (LzmaCompress((UINT8*)newData.constData(), newData.size(), compressed, &compressedSize) != ERR_SUCCESS) {
|
||||
delete[] compressed;
|
||||
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
|
||||
}
|
||||
compressedData = header.append(QByteArray((const char*) compressed, compressedSize));
|
||||
delete[] compressed;
|
||||
return ERR_SUCCESS;
|
||||
|
@ -47,8 +47,6 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
|
||||
return item->data(index.column());
|
||||
else
|
||||
return item->info();
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
|
||||
@ -366,8 +364,10 @@ QModelIndex TreeModel::addItem(const UINT8 type, const UINT8 subtype, const UINT
|
||||
emit layoutAboutToBeChanged();
|
||||
parentItem->insertChildAfter(item, newItem);
|
||||
}
|
||||
else
|
||||
else {
|
||||
delete newItem;
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
emit layoutChanged();
|
||||
|
||||
|
14
uefitool.cpp
14
uefitool.cpp
@ -205,6 +205,9 @@ void UEFITool::insert(const UINT8 mode)
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.trimmed().isEmpty())
|
||||
return;
|
||||
|
||||
QFileInfo fileInfo = QFileInfo(path);
|
||||
if (!fileInfo.exists()) {
|
||||
ui->statusBar->showMessage(tr("Please select existing file"));
|
||||
@ -304,6 +307,9 @@ void UEFITool::replace(const UINT8 mode)
|
||||
else
|
||||
return;
|
||||
|
||||
if (path.trimmed().isEmpty())
|
||||
return;
|
||||
|
||||
QFileInfo fileInfo = QFileInfo(path);
|
||||
if (!fileInfo.exists()) {
|
||||
ui->statusBar->showMessage(tr("Please select existing file"));
|
||||
@ -405,6 +411,9 @@ void UEFITool::extract(const UINT8 mode)
|
||||
else
|
||||
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
|
||||
|
||||
if (path.trimmed().isEmpty())
|
||||
return;
|
||||
|
||||
QByteArray extracted;
|
||||
UINT8 result = ffsEngine->extract(index, extracted, mode);
|
||||
if (result) {
|
||||
@ -421,7 +430,6 @@ void UEFITool::extract(const UINT8 mode)
|
||||
outputFile.resize(0);
|
||||
outputFile.write(extracted);
|
||||
outputFile.close();
|
||||
|
||||
}
|
||||
|
||||
void UEFITool::about()
|
||||
@ -484,7 +492,11 @@ void UEFITool::openImageFile()
|
||||
|
||||
void UEFITool::openImageFile(QString path)
|
||||
{
|
||||
if (path.trimmed().isEmpty())
|
||||
return;
|
||||
|
||||
QFileInfo fileInfo = QFileInfo(path);
|
||||
|
||||
if (!fileInfo.exists()) {
|
||||
ui->statusBar->showMessage(tr("Please select existing file"));
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user