From aae044a130599427e3562fe5736d7b2d42777272 Mon Sep 17 00:00:00 2001 From: "Vineel Kovvuri[MSFT]" Date: Fri, 25 Oct 2024 16:37:01 -0700 Subject: [PATCH] EmbeddedPkg: CodeQL Fixes. Makes changes to comply with alerts raised by CodeQL. Most of the issues here fall into the following two categories: 1. Potential use of uninitialized pointer. 2. Inconsistent integer width in comparison. Co-authored-by: Taylor Beebe Co-authored-by: Ken Lautner Co-authored-by: Bret Barkelew Signed-off-by: Vineel Kovvuri[MSFT] --- EmbeddedPkg/Library/PrePiHobLib/Hob.c | 3 +++ EmbeddedPkg/Library/PrePiLib/FwVol.c | 2 +- EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/EmbeddedPkg/Library/PrePiHobLib/Hob.c b/EmbeddedPkg/Library/PrePiHobLib/Hob.c index 9c450c0c87ec..a394ca00b486 100644 --- a/EmbeddedPkg/Library/PrePiHobLib/Hob.c +++ b/EmbeddedPkg/Library/PrePiHobLib/Hob.c @@ -498,6 +498,9 @@ BuildGuidDataHob ( ASSERT (Data != NULL || DataLength == 0); HobData = BuildGuidHob (Guid, DataLength); + if (HobData == NULL) { + return NULL; + } return CopyMem (HobData, Data, DataLength); } diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/PrePiLib/FwVol.c index 7739a5c8aae7..cfb1ff46b7d9 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -283,7 +283,7 @@ FfsProcessSection ( { EFI_STATUS Status; UINT32 SectionLength; - UINT32 ParsedLength; + UINTN ParsedLength; EFI_COMPRESSION_SECTION *CompressionSection; EFI_COMPRESSION_SECTION2 *CompressionSection2; UINT32 DstBufferSize; diff --git a/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c b/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c index 32944a8d9d25..2a15f23771ef 100644 --- a/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c +++ b/EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOut.c @@ -504,6 +504,9 @@ OutputString ( Size = StrLen (String) + 1; OutputString = AllocatePool (Size); + if (OutputString == NULL) { + return EFI_OUT_OF_RESOURCES; + } // If there is any non-ascii characters in String buffer then replace it with '?' // Eventually, UnicodeStrToAsciiStr API should be fixed.