Version 0.17.8

-fixed bugs found by first scan with Coverity Scan
This commit is contained in:
Nikolaj Schlej 2014-04-18 14:18:11 +02:00
parent 706b0088e3
commit 1df4e4f9d8
3 changed files with 37 additions and 16 deletions

View file

@ -28,6 +28,8 @@ FfsEngine::FfsEngine(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
model = new TreeModel(); model = new TreeModel();
oldPeiCoreEntryPoint = 0;
newPeiCoreEntryPoint = 0;
} }
FfsEngine::~FfsEngine(void) FfsEngine::~FfsEngine(void)
@ -71,8 +73,6 @@ bool FfsEngine::hasIntersection(const UINT32 begin1, const UINT32 end1, const UI
// Firmware image parsing // Firmware image parsing
UINT8 FfsEngine::parseImageFile(const QByteArray & buffer) UINT8 FfsEngine::parseImageFile(const QByteArray & buffer)
{ {
oldPeiCoreEntryPoint = 0;
newPeiCoreEntryPoint = 0;
UINT32 capsuleHeaderSize = 0; UINT32 capsuleHeaderSize = 0;
FLASH_DESCRIPTOR_HEADER* descriptorHeader = NULL; FLASH_DESCRIPTOR_HEADER* descriptorHeader = NULL;
QModelIndex index; QModelIndex index;
@ -828,7 +828,7 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
// Check file state // Check file state
// Determine file erase polarity // 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 // Check file erase polarity to be the same as parent erase polarity
if (erasePolarity != ERASE_POLARITY_UNKNOWN && (bool) erasePolarity != fileErasePolarity) { 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 (ERR_SUCCESS != EfiDecompress(data, dataSize, decompressed, decompressedSize, scratch, scratchSize)) {
if (algorithm) if (algorithm)
*algorithm = COMPRESSION_ALGORITHM_UNKNOWN; *algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
delete[] decompressed;
delete[] scratch;
return ERR_STANDARD_DECOMPRESSION_FAILED; return ERR_STANDARD_DECOMPRESSION_FAILED;
} }
else if (algorithm) else if (algorithm)
@ -1712,10 +1714,8 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
decompressedData = QByteArray((const char*) decompressed, decompressedSize); decompressedData = QByteArray((const char*) decompressed, decompressedSize);
// Free allocated memory
delete[] decompressed; delete[] decompressed;
delete[] scratch; delete[] scratch;
return ERR_SUCCESS; return ERR_SUCCESS;
case EFI_CUSTOMIZED_COMPRESSION: case EFI_CUSTOMIZED_COMPRESSION:
// Get buffer sizes // Get buffer sizes
@ -1743,13 +1743,16 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
data += shittySectionSize; data += shittySectionSize;
// Get info again // Get info again
if (ERR_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) if (ERR_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) {
delete[] decompressed;
return ERR_CUSTOMIZED_DECOMPRESSION_FAILED; return ERR_CUSTOMIZED_DECOMPRESSION_FAILED;
}
// Decompress section data again // Decompress section data again
if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) { if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) {
if (algorithm) if (algorithm)
*algorithm = COMPRESSION_ALGORITHM_UNKNOWN; *algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
delete[] decompressed;
return ERR_CUSTOMIZED_DECOMPRESSION_FAILED; return ERR_CUSTOMIZED_DECOMPRESSION_FAILED;
} }
else { else {
@ -1764,9 +1767,7 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
decompressedData = QByteArray((const char*) decompressed, decompressedSize); decompressedData = QByteArray((const char*) decompressed, decompressedSize);
} }
// Free memory
delete[] decompressed; delete[] decompressed;
return ERR_SUCCESS; return ERR_SUCCESS;
default: default:
msg(tr("decompress: Unknown compression type (%1)").arg(compressionType)); 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) if (EfiCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED; return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize]; 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; return ERR_STANDARD_COMPRESSION_FAILED;
}
compressedData = QByteArray((const char*) compressed, compressedSize); compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed; delete[] compressed;
return ERR_SUCCESS; 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) if (TianoCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED; return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize]; 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; return ERR_STANDARD_COMPRESSION_FAILED;
}
compressedData = QByteArray((const char*) compressed, compressedSize); compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed; delete[] compressed;
return ERR_SUCCESS; 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) if (LzmaCompress((const UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_CUSTOMIZED_COMPRESSION_FAILED; return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize]; 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; return ERR_CUSTOMIZED_COMPRESSION_FAILED;
}
compressedData = QByteArray((const char*) compressed, compressedSize); compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed; delete[] compressed;
return ERR_SUCCESS; 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) if (LzmaCompress((UINT8*) newData.constData(), newData.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_CUSTOMIZED_COMPRESSION_FAILED; return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize]; 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; return ERR_CUSTOMIZED_COMPRESSION_FAILED;
}
compressedData = header.append(QByteArray((const char*) compressed, compressedSize)); compressedData = header.append(QByteArray((const char*) compressed, compressedSize));
delete[] compressed; delete[] compressed;
return ERR_SUCCESS; return ERR_SUCCESS;

View file

@ -47,8 +47,6 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
return item->data(index.column()); return item->data(index.column());
else else
return item->info(); return item->info();
return QVariant();
} }
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const 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(); emit layoutAboutToBeChanged();
parentItem->insertChildAfter(item, newItem); parentItem->insertChildAfter(item, newItem);
} }
else else {
delete newItem;
return QModelIndex(); return QModelIndex();
}
emit layoutChanged(); emit layoutChanged();

View file

@ -205,6 +205,9 @@ void UEFITool::insert(const UINT8 mode)
return; return;
} }
if (path.trimmed().isEmpty())
return;
QFileInfo fileInfo = QFileInfo(path); QFileInfo fileInfo = QFileInfo(path);
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
ui->statusBar->showMessage(tr("Please select existing file")); ui->statusBar->showMessage(tr("Please select existing file"));
@ -304,6 +307,9 @@ void UEFITool::replace(const UINT8 mode)
else else
return; return;
if (path.trimmed().isEmpty())
return;
QFileInfo fileInfo = QFileInfo(path); QFileInfo fileInfo = QFileInfo(path);
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
ui->statusBar->showMessage(tr("Please select existing file")); ui->statusBar->showMessage(tr("Please select existing file"));
@ -405,6 +411,9 @@ void UEFITool::extract(const UINT8 mode)
else else
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)"); path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
if (path.trimmed().isEmpty())
return;
QByteArray extracted; QByteArray extracted;
UINT8 result = ffsEngine->extract(index, extracted, mode); UINT8 result = ffsEngine->extract(index, extracted, mode);
if (result) { if (result) {
@ -421,7 +430,6 @@ void UEFITool::extract(const UINT8 mode)
outputFile.resize(0); outputFile.resize(0);
outputFile.write(extracted); outputFile.write(extracted);
outputFile.close(); outputFile.close();
} }
void UEFITool::about() void UEFITool::about()
@ -484,7 +492,11 @@ void UEFITool::openImageFile()
void UEFITool::openImageFile(QString path) void UEFITool::openImageFile(QString path)
{ {
if (path.trimmed().isEmpty())
return;
QFileInfo fileInfo = QFileInfo(path); QFileInfo fileInfo = QFileInfo(path);
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
ui->statusBar->showMessage(tr("Please select existing file")); ui->statusBar->showMessage(tr("Please select existing file"));
return; return;