Merge pull request #272 from LongSoft/PR/fix_new_coverity_warnings

Fix new warnings from Coverity Scan
This commit is contained in:
Nikolaj Schlej 2022-08-25 07:09:58 +02:00 committed by GitHub
commit 820e3ea65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 24 deletions

View File

@ -3630,7 +3630,7 @@ USTATUS FfsParser::parseVendorHashFile(const UByteArray & fileGuid, const UModel
protectedRangesFound = true; protectedRangesFound = true;
const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(header + 1) + i; const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(header + 1) + i;
BG_PROTECTED_RANGE range; BG_PROTECTED_RANGE range = {};
range.Offset = entry->Offset; range.Offset = entry->Offset;
range.Size = entry->Size; range.Size = entry->Size;
range.Hash = UByteArray((const char*)entry->Hash, sizeof(entry->Hash)); range.Hash = UByteArray((const char*)entry->Hash, sizeof(entry->Hash));
@ -3670,7 +3670,7 @@ USTATUS FfsParser::parseVendorHashFile(const UByteArray & fileGuid, const UModel
for (UINT32 i = 0; i < NumEntries; i++) { for (UINT32 i = 0; i < NumEntries; i++) {
protectedRangesFound = true; protectedRangesFound = true;
const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(body.constData()) + i; const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(body.constData()) + i;
BG_PROTECTED_RANGE range; BG_PROTECTED_RANGE range = {};
range.Offset = entry->Offset; range.Offset = entry->Offset;
range.Size = entry->Size; range.Size = entry->Size;
range.Hash = UByteArray((const char*)entry->Hash, sizeof(entry->Hash)); range.Hash = UByteArray((const char*)entry->Hash, sizeof(entry->Hash));
@ -3701,7 +3701,7 @@ USTATUS FfsParser::parseVendorHashFile(const UByteArray & fileGuid, const UModel
} }
securityInfo += UString("\n------------------------------------------------------------------------\n\n"); securityInfo += UString("\n------------------------------------------------------------------------\n\n");
BG_PROTECTED_RANGE range; BG_PROTECTED_RANGE range = {};
range.Offset = 0; range.Offset = 0;
range.Size = entry->Size; range.Size = entry->Size;
range.Hash = UByteArray((const char*)entry->Hash, sizeof(entry->Hash)); range.Hash = UByteArray((const char*)entry->Hash, sizeof(entry->Hash));
@ -4216,7 +4216,7 @@ USTATUS FfsParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic
// Check for non-empry PostIbbHash // Check for non-empry PostIbbHash
UByteArray postIbbHash((const char*)elementHeader->IbbHash.HashBuffer, sizeof(elementHeader->IbbHash.HashBuffer)); UByteArray postIbbHash((const char*)elementHeader->IbbHash.HashBuffer, sizeof(elementHeader->IbbHash.HashBuffer));
if (postIbbHash.count('\x00') != postIbbHash.size() && postIbbHash.count('\xFF') != postIbbHash.size()) { if (postIbbHash.count('\x00') != postIbbHash.size() && postIbbHash.count('\xFF') != postIbbHash.size()) {
BG_PROTECTED_RANGE range; BG_PROTECTED_RANGE range = {};
range.Type = BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_POST_IBB; range.Type = BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_POST_IBB;
range.Hash = postIbbHash; range.Hash = postIbbHash;
bgProtectedRanges.push_back(range); bgProtectedRanges.push_back(range);
@ -4236,7 +4236,7 @@ USTATUS FfsParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic
securityInfo += usprintf("Flags: %04Xh Address: %08Xh Size: %08Xh\n", securityInfo += usprintf("Flags: %04Xh Address: %08Xh Size: %08Xh\n",
segments[i].Flags, segments[i].Base, segments[i].Size); segments[i].Flags, segments[i].Base, segments[i].Size);
if (segments[i].Flags == BG_IBB_SEGMENT_FLAG_IBB) { if (segments[i].Flags == BG_IBB_SEGMENT_FLAG_IBB) {
BG_PROTECTED_RANGE range; BG_PROTECTED_RANGE range = {};
range.Offset = segments[i].Base; range.Offset = segments[i].Base;
range.Size = segments[i].Size; range.Size = segments[i].Size;
range.Type = BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB; range.Type = BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB;
@ -4269,7 +4269,7 @@ USTATUS FfsParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic
} }
securityInfo += UString("\n"); securityInfo += UString("\n");
BG_PROTECTED_RANGE range; BG_PROTECTED_RANGE range = {};
range.Offset = entries[i].Address; range.Offset = entries[i].Address;
range.Size = entries[i].Size; range.Size = entries[i].Size;
range.Hash = UByteArray((const char*)entries[i].Hash, sizeof(entries[i].Hash)); range.Hash = UByteArray((const char*)entries[i].Hash, sizeof(entries[i].Hash));
@ -4549,7 +4549,8 @@ USTATUS FfsParser::parseBpdtRegion(const UByteArray & region, const UINT32 local
// Add partition table entries // Add partition table entries
std::vector<BPDT_PARTITION_INFO> partitions; std::vector<BPDT_PARTITION_INFO> partitions;
const BPDT_ENTRY* firstPtEntry = (const BPDT_ENTRY*)((const UINT8*)ptHeader + sizeof(BPDT_HEADER)); const BPDT_ENTRY* firstPtEntry = (const BPDT_ENTRY*)((const UINT8*)ptHeader + sizeof(BPDT_HEADER));
for (UINT16 i = 0; i < ptHeader->NumEntries; i++) { UINT16 numEntries = ptHeader->NumEntries;
for (UINT16 i = 0; i < numEntries; i++) {
// Populate entry header // Populate entry header
const BPDT_ENTRY* ptEntry = firstPtEntry + i; const BPDT_ENTRY* ptEntry = firstPtEntry + i;
@ -4573,7 +4574,7 @@ USTATUS FfsParser::parseBpdtRegion(const UByteArray & region, const UINT32 local
if (ptEntry->Offset != 0 && ptEntry->Offset != 0xFFFFFFFF && ptEntry->Size != 0) { if (ptEntry->Offset != 0 && ptEntry->Offset != 0xFFFFFFFF && ptEntry->Size != 0) {
// Add to partitions vector // Add to partitions vector
BPDT_PARTITION_INFO partition; BPDT_PARTITION_INFO partition = {};
partition.type = Types::BpdtPartition; partition.type = Types::BpdtPartition;
partition.ptEntry = *ptEntry; partition.ptEntry = *ptEntry;
partition.ptEntry.Offset -= sbpdtOffsetFixup; partition.ptEntry.Offset -= sbpdtOffsetFixup;
@ -4601,7 +4602,7 @@ make_partition_table_consistent:
std::sort(partitions.begin(), partitions.end()); std::sort(partitions.begin(), partitions.end());
// Check for intersections and paddings between partitions // Check for intersections and paddings between partitions
BPDT_PARTITION_INFO padding; BPDT_PARTITION_INFO padding = {};
// Check intersection with the partition table header // Check intersection with the partition table header
if (partitions.front().ptEntry.Offset < ptSize) { if (partitions.front().ptEntry.Offset < ptSize) {

View File

@ -105,7 +105,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex &
{ {
// Check region size // Check region size
if ((UINT32)region.size() < sizeof(FPT_HEADER)) { if ((UINT32)region.size() < sizeof(FPT_HEADER)) {
msg(usprintf("%s: region too small to fit FPT header", __FUNCTION__), parent); msg(usprintf("%s: region too small to fit the FPT partition table header", __FUNCTION__), parent);
return U_INVALID_ME_PARTITION_TABLE; return U_INVALID_ME_PARTITION_TABLE;
} }
@ -122,7 +122,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex &
UINT32 ptBodySize = ptHeader->NumEntries * sizeof(FPT_HEADER_ENTRY); UINT32 ptBodySize = ptHeader->NumEntries * sizeof(FPT_HEADER_ENTRY);
UINT32 ptSize = romBypassVectorSize + sizeof(FPT_HEADER) + ptBodySize; UINT32 ptSize = romBypassVectorSize + sizeof(FPT_HEADER) + ptBodySize;
if ((UINT32)region.size() < ptSize) { if ((UINT32)region.size() < ptSize) {
msg(usprintf("%s: ME region too small to fit FPT partition table", __FUNCTION__), parent); msg(usprintf("%s: ME region too small to fit the FPT partition table", __FUNCTION__), parent);
return U_INVALID_ME_PARTITION_TABLE; return U_INVALID_ME_PARTITION_TABLE;
} }
@ -154,8 +154,9 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex &
// Add partition table entries // Add partition table entries
std::vector<FPT_PARTITION_INFO> partitions; std::vector<FPT_PARTITION_INFO> partitions;
UINT32 offset = (UINT32)header.size(); UINT32 offset = (UINT32)header.size();
UINT32 numEntries = ptHeader->NumEntries;
const FPT_HEADER_ENTRY* firstPtEntry = (const FPT_HEADER_ENTRY*)(region.constData() + offset); const FPT_HEADER_ENTRY* firstPtEntry = (const FPT_HEADER_ENTRY*)(region.constData() + offset);
for (UINT8 i = 0; i < ptHeader->NumEntries; i++) { for (UINT32 i = 0; i < numEntries; i++) {
// Populate entry header // Populate entry header
const FPT_HEADER_ENTRY* ptEntry = firstPtEntry + i; const FPT_HEADER_ENTRY* ptEntry = firstPtEntry + i;
@ -177,7 +178,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex &
// Add valid partitions // Add valid partitions
if (type == Subtypes::ValidFptEntry) { // Skip absent and invalid partitions if (type == Subtypes::ValidFptEntry) { // Skip absent and invalid partitions
// Add to partitions vector // Add to partitions vector
FPT_PARTITION_INFO partition; FPT_PARTITION_INFO partition = {};
partition.type = Types::FptPartition; partition.type = Types::FptPartition;
partition.ptEntry = *ptEntry; partition.ptEntry = *ptEntry;
partition.index = entryIndex; partition.index = entryIndex;
@ -190,7 +191,7 @@ make_partition_table_consistent:
std::sort(partitions.begin(), partitions.end()); std::sort(partitions.begin(), partitions.end());
// Check for intersections and paddings between partitions // Check for intersections and paddings between partitions
FPT_PARTITION_INFO padding; FPT_PARTITION_INFO padding = {};
// Check intersection with the partition table header // Check intersection with the partition table header
if (partitions.front().ptEntry.Offset < ptSize) { if (partitions.front().ptEntry.Offset < ptSize) {
@ -328,7 +329,7 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex
std::vector<IFWI_PARTITION_INFO> partitions; std::vector<IFWI_PARTITION_INFO> partitions;
// Add data partition // Add data partition
{ {
IFWI_PARTITION_INFO partition; IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition; partition.type = Types::IfwiPartition;
partition.subtype = Subtypes::DataIfwiPartition; partition.subtype = Subtypes::DataIfwiPartition;
partition.ptEntry = ifwiHeader->DataPartition; partition.ptEntry = ifwiHeader->DataPartition;
@ -337,7 +338,7 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex
// Add boot partitions // Add boot partitions
for (UINT8 i = 0 ; i < 4; i++) { for (UINT8 i = 0 ; i < 4; i++) {
if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) { if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) {
IFWI_PARTITION_INFO partition; IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition; partition.type = Types::IfwiPartition;
partition.subtype = Subtypes::BootIfwiPartition; partition.subtype = Subtypes::BootIfwiPartition;
partition.ptEntry = ifwiHeader->BootPartition[i]; partition.ptEntry = ifwiHeader->BootPartition[i];
@ -350,7 +351,7 @@ make_partition_table_consistent:
std::sort(partitions.begin(), partitions.end()); std::sort(partitions.begin(), partitions.end());
// Check for intersections and paddings between partitions // Check for intersections and paddings between partitions
IFWI_PARTITION_INFO padding; IFWI_PARTITION_INFO padding = {};
// Check intersection with the partition table header // Check intersection with the partition table header
if (partitions.front().ptEntry.Offset < ptSize) { if (partitions.front().ptEntry.Offset < ptSize) {
@ -502,7 +503,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex
std::vector<IFWI_PARTITION_INFO> partitions; std::vector<IFWI_PARTITION_INFO> partitions;
// Add data partition // Add data partition
{ {
IFWI_PARTITION_INFO partition; IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition; partition.type = Types::IfwiPartition;
partition.subtype = Subtypes::DataIfwiPartition; partition.subtype = Subtypes::DataIfwiPartition;
partition.ptEntry = ifwiHeader->DataPartition; partition.ptEntry = ifwiHeader->DataPartition;
@ -511,7 +512,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex
// Add boot partitions // Add boot partitions
for (UINT8 i = 0 ; i < 4; i++) { for (UINT8 i = 0 ; i < 4; i++) {
if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) { if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) {
IFWI_PARTITION_INFO partition; IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition; partition.type = Types::IfwiPartition;
partition.subtype = Subtypes::BootIfwiPartition; partition.subtype = Subtypes::BootIfwiPartition;
partition.ptEntry = ifwiHeader->BootPartition[i]; partition.ptEntry = ifwiHeader->BootPartition[i];
@ -520,7 +521,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex
} }
// Add temp page // Add temp page
if (ifwiHeader->TempPage.Offset != 0 && ifwiHeader->TempPage.Offset != 0xFFFFFFFF) { if (ifwiHeader->TempPage.Offset != 0 && ifwiHeader->TempPage.Offset != 0xFFFFFFFF) {
IFWI_PARTITION_INFO partition; IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition; partition.type = Types::IfwiPartition;
partition.subtype = Subtypes::DataPadding; partition.subtype = Subtypes::DataPadding;
partition.ptEntry = ifwiHeader->TempPage; partition.ptEntry = ifwiHeader->TempPage;
@ -532,7 +533,7 @@ make_partition_table_consistent:
std::sort(partitions.begin(), partitions.end()); std::sort(partitions.begin(), partitions.end());
// Check for intersections and paddings between partitions // Check for intersections and paddings between partitions
IFWI_PARTITION_INFO padding; IFWI_PARTITION_INFO padding = {};
// Check intersection with the partition table header // Check intersection with the partition table header
if (partitions.front().ptEntry.Offset < ptSize) { if (partitions.front().ptEntry.Offset < ptSize) {

View File

@ -682,9 +682,9 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
break; break;
} }
else if (*currentPos == OEM_ACTIVATION_MARKER_WINDOWS_FLAG_PART1) { // SLIC marker else if (*currentPos == OEM_ACTIVATION_MARKER_WINDOWS_FLAG_PART1) { // SLIC marker
if (offset >= dataSize - sizeof(UINT64) || if (offset < 26
*(const UINT64*)currentPos != OEM_ACTIVATION_MARKER_WINDOWS_FLAG || || offset >= dataSize - sizeof(UINT64)
offset < 26) // Check full windows flag and structure size || *(const UINT64*)currentPos != OEM_ACTIVATION_MARKER_WINDOWS_FLAG) // Check full windows flag and structure size
continue; continue;
const OEM_ACTIVATION_MARKER* markerHeader = (const OEM_ACTIVATION_MARKER*)(volume.constData() + offset - 26); const OEM_ACTIVATION_MARKER* markerHeader = (const OEM_ACTIVATION_MARKER*)(volume.constData() + offset - 26);