From e85fb741ee39021101e7f1134612f640eb02c975 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Thu, 25 Aug 2022 06:49:10 +0200 Subject: [PATCH] Fix new warnings from Coverity Scan --- common/ffsparser.cpp | 19 ++++++++++--------- common/meparser.cpp | 25 +++++++++++++------------ common/nvramparser.cpp | 6 +++--- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index 0e7dae8..adfd32b 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -3630,7 +3630,7 @@ USTATUS FfsParser::parseVendorHashFile(const UByteArray & fileGuid, const UModel protectedRangesFound = true; 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.Size = entry->Size; 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++) { protectedRangesFound = true; 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.Size = entry->Size; 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"); - BG_PROTECTED_RANGE range; + BG_PROTECTED_RANGE range = {}; range.Offset = 0; range.Size = entry->Size; 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 UByteArray postIbbHash((const char*)elementHeader->IbbHash.HashBuffer, sizeof(elementHeader->IbbHash.HashBuffer)); 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.Hash = postIbbHash; bgProtectedRanges.push_back(range); @@ -4236,7 +4236,7 @@ USTATUS FfsParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic securityInfo += usprintf("Flags: %04Xh Address: %08Xh Size: %08Xh\n", segments[i].Flags, segments[i].Base, segments[i].Size); if (segments[i].Flags == BG_IBB_SEGMENT_FLAG_IBB) { - BG_PROTECTED_RANGE range; + BG_PROTECTED_RANGE range = {}; range.Offset = segments[i].Base; range.Size = segments[i].Size; range.Type = BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB; @@ -4269,7 +4269,7 @@ USTATUS FfsParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic } securityInfo += UString("\n"); - BG_PROTECTED_RANGE range; + BG_PROTECTED_RANGE range = {}; range.Offset = entries[i].Address; range.Size = entries[i].Size; 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 std::vector partitions; 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 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) { // Add to partitions vector - BPDT_PARTITION_INFO partition; + BPDT_PARTITION_INFO partition = {}; partition.type = Types::BpdtPartition; partition.ptEntry = *ptEntry; partition.ptEntry.Offset -= sbpdtOffsetFixup; @@ -4601,7 +4602,7 @@ make_partition_table_consistent: std::sort(partitions.begin(), partitions.end()); // Check for intersections and paddings between partitions - BPDT_PARTITION_INFO padding; + BPDT_PARTITION_INFO padding = {}; // Check intersection with the partition table header if (partitions.front().ptEntry.Offset < ptSize) { diff --git a/common/meparser.cpp b/common/meparser.cpp index 1b3dc1f..ecdd488 100755 --- a/common/meparser.cpp +++ b/common/meparser.cpp @@ -105,7 +105,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex & { // Check region size 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; } @@ -122,7 +122,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex & UINT32 ptBodySize = ptHeader->NumEntries * sizeof(FPT_HEADER_ENTRY); UINT32 ptSize = romBypassVectorSize + sizeof(FPT_HEADER) + ptBodySize; 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; } @@ -154,8 +154,9 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex & // Add partition table entries std::vector partitions; UINT32 offset = (UINT32)header.size(); + UINT32 numEntries = ptHeader->NumEntries; 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 const FPT_HEADER_ENTRY* ptEntry = firstPtEntry + i; @@ -177,7 +178,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex & // Add valid partitions if (type == Subtypes::ValidFptEntry) { // Skip absent and invalid partitions // Add to partitions vector - FPT_PARTITION_INFO partition; + FPT_PARTITION_INFO partition = {}; partition.type = Types::FptPartition; partition.ptEntry = *ptEntry; partition.index = entryIndex; @@ -190,7 +191,7 @@ make_partition_table_consistent: std::sort(partitions.begin(), partitions.end()); // Check for intersections and paddings between partitions - FPT_PARTITION_INFO padding; + FPT_PARTITION_INFO padding = {}; // Check intersection with the partition table header if (partitions.front().ptEntry.Offset < ptSize) { @@ -328,7 +329,7 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex std::vector partitions; // Add data partition { - IFWI_PARTITION_INFO partition; + IFWI_PARTITION_INFO partition = {}; partition.type = Types::IfwiPartition; partition.subtype = Subtypes::DataIfwiPartition; partition.ptEntry = ifwiHeader->DataPartition; @@ -337,7 +338,7 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex // Add boot partitions for (UINT8 i = 0 ; i < 4; i++) { if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) { - IFWI_PARTITION_INFO partition; + IFWI_PARTITION_INFO partition = {}; partition.type = Types::IfwiPartition; partition.subtype = Subtypes::BootIfwiPartition; partition.ptEntry = ifwiHeader->BootPartition[i]; @@ -350,7 +351,7 @@ make_partition_table_consistent: std::sort(partitions.begin(), partitions.end()); // Check for intersections and paddings between partitions - IFWI_PARTITION_INFO padding; + IFWI_PARTITION_INFO padding = {}; // Check intersection with the partition table header if (partitions.front().ptEntry.Offset < ptSize) { @@ -502,7 +503,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex std::vector partitions; // Add data partition { - IFWI_PARTITION_INFO partition; + IFWI_PARTITION_INFO partition = {}; partition.type = Types::IfwiPartition; partition.subtype = Subtypes::DataIfwiPartition; partition.ptEntry = ifwiHeader->DataPartition; @@ -511,7 +512,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex // Add boot partitions for (UINT8 i = 0 ; i < 4; i++) { if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) { - IFWI_PARTITION_INFO partition; + IFWI_PARTITION_INFO partition = {}; partition.type = Types::IfwiPartition; partition.subtype = Subtypes::BootIfwiPartition; partition.ptEntry = ifwiHeader->BootPartition[i]; @@ -520,7 +521,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex } // Add temp page if (ifwiHeader->TempPage.Offset != 0 && ifwiHeader->TempPage.Offset != 0xFFFFFFFF) { - IFWI_PARTITION_INFO partition; + IFWI_PARTITION_INFO partition = {}; partition.type = Types::IfwiPartition; partition.subtype = Subtypes::DataPadding; partition.ptEntry = ifwiHeader->TempPage; @@ -532,7 +533,7 @@ make_partition_table_consistent: std::sort(partitions.begin(), partitions.end()); // Check for intersections and paddings between partitions - IFWI_PARTITION_INFO padding; + IFWI_PARTITION_INFO padding = {}; // Check intersection with the partition table header if (partitions.front().ptEntry.Offset < ptSize) { diff --git a/common/nvramparser.cpp b/common/nvramparser.cpp index e4ae149..69b65c4 100755 --- a/common/nvramparser.cpp +++ b/common/nvramparser.cpp @@ -682,9 +682,9 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray & break; } else if (*currentPos == OEM_ACTIVATION_MARKER_WINDOWS_FLAG_PART1) { // SLIC marker - if (offset >= dataSize - sizeof(UINT64) || - *(const UINT64*)currentPos != OEM_ACTIVATION_MARKER_WINDOWS_FLAG || - offset < 26) // Check full windows flag and structure size + if (offset < 26 + || offset >= dataSize - sizeof(UINT64) + || *(const UINT64*)currentPos != OEM_ACTIVATION_MARKER_WINDOWS_FLAG) // Check full windows flag and structure size continue; const OEM_ACTIVATION_MARKER* markerHeader = (const OEM_ACTIVATION_MARKER*)(volume.constData() + offset - 26);