Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeQL errors #488

Merged
12 changes: 11 additions & 1 deletion CryptoPkg/Test/UnitTest/Library/BaseCryptLib/UnitTestMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ UefiTestMain (
UNIT_TEST_FRAMEWORK_HANDLE Framework;

DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION));
CreateUnitTest (UNIT_TEST_NAME, UNIT_TEST_VERSION, &Framework);
// MU_CHANGE [BEGIN] - CodeQL change
Status = CreateUnitTest (UNIT_TEST_NAME, UNIT_TEST_VERSION, &Framework);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestsfor BaseCryptLib Tests! Status = %r\n", Status));
goto Done;
}

// MU_CHANGE [END] - CodeQL change

//
// Execute the tests.
//
Status = RunAllTestSuites (Framework);

// MU_CHANGE [BEGIN] - CodeQL change
Done:
// MU_CHANGE [END] - CodeQL change
if (Framework) {
FreeUnitTestFramework (Framework);
}
Expand Down
13 changes: 3 additions & 10 deletions MdeModulePkg/Core/Pei/Ppi/Ppi.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,9 @@ ConvertPpiPointersFv (

Guid = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Guid;
for (GuidIndex = 0; GuidIndex < ARRAY_SIZE (GuidCheckList); ++GuidIndex) {
//
// Don't use CompareGuid function here for performance reasons.
// Instead we compare the GUID as INT32 at a time and branch
// on the first failed comparison.
//
if ((((INT32 *)Guid)[0] == ((INT32 *)GuidCheckList[GuidIndex])[0]) &&
(((INT32 *)Guid)[1] == ((INT32 *)GuidCheckList[GuidIndex])[1]) &&
(((INT32 *)Guid)[2] == ((INT32 *)GuidCheckList[GuidIndex])[2]) &&
(((INT32 *)Guid)[3] == ((INT32 *)GuidCheckList[GuidIndex])[3]))
{
// MU_CHANGE [BEGIN] - CodeQL change
if (CompareGuid (Guid, GuidCheckList[GuidIndex]) == 0) {
// MU_CHANGE [END] - CodeQL change
FvInfoPpi = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Ppi;
DEBUG ((DEBUG_VERBOSE, " FvInfo: %p -> ", FvInfoPpi->FvInfo));
if ((UINTN)FvInfoPpi->FvInfo == OrgFvHandle) {
Expand Down
74 changes: 66 additions & 8 deletions MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,11 @@ GetFullSmramRanges (
EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
UINTN MaxCount;
BOOLEAN Rescan;
// MU_CHANGE [BEGIN] - CodeQL change
BOOLEAN Failed;

Failed = FALSE;
// MU_CHANGE [END] - CodeQL change

//
// Get SMM Configuration Protocol if it is present.
Expand Down Expand Up @@ -1481,7 +1486,14 @@ GetFullSmramRanges (
*FullSmramRangeCount = SmramRangeCount + AdditionSmramRangeCount;
Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocateZeroPool (Size);
ASSERT (FullSmramRanges != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (FullSmramRanges == NULL) {
ASSERT (FullSmramRanges != NULL);
Failed = TRUE;
goto Done;
}

// MU_CHANGE [END] - CodeQL change

Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, FullSmramRanges);
ASSERT_EFI_ERROR (Status);
Expand Down Expand Up @@ -1528,18 +1540,41 @@ GetFullSmramRanges (

Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *)AllocatePool (Size);
ASSERT (SmramReservedRanges != NULL);

// MU_CHANGE [BEGIN] - CodeQL change
if (SmramReservedRanges == NULL) {
ASSERT (SmramReservedRanges != NULL);
Failed = TRUE;
goto Done;
}

// MU_CHANGE [END] - CodeQL change

for (Index = 0; Index < SmramReservedCount; Index++) {
CopyMem (&SmramReservedRanges[Index], &SmmConfiguration->SmramReservedRegions[Index], sizeof (EFI_SMM_RESERVED_SMRAM_REGION));
}

Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
ASSERT (TempSmramRanges != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (TempSmramRanges == NULL) {
ASSERT (TempSmramRanges != NULL);
Failed = TRUE;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
TempSmramRangeCount = 0;

SmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
ASSERT (SmramRanges != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (SmramRanges == NULL) {
ASSERT (SmramRanges != NULL);
Failed = TRUE;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, SmramRanges);
ASSERT_EFI_ERROR (Status);

Expand Down Expand Up @@ -1596,7 +1631,14 @@ GetFullSmramRanges (
// Sort the entries
//
FullSmramRanges = AllocateZeroPool ((TempSmramRangeCount + AdditionSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR));
ASSERT (FullSmramRanges != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (FullSmramRanges == NULL) {
ASSERT (FullSmramRanges != NULL);
Failed = TRUE;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
*FullSmramRangeCount = 0;
do {
for (Index = 0; Index < TempSmramRangeCount; Index++) {
Expand All @@ -1620,9 +1662,25 @@ GetFullSmramRanges (
ASSERT (*FullSmramRangeCount == TempSmramRangeCount);
*FullSmramRangeCount += AdditionSmramRangeCount;

FreePool (SmramRanges);
FreePool (SmramReservedRanges);
FreePool (TempSmramRanges);
// MU_CHANGE [BEGIN] - CodeQL change
Done:
if (SmramRanges != NULL) {
FreePool (SmramRanges);
}

if (SmramReservedRanges != NULL) {
FreePool (SmramReservedRanges);
}

if (TempSmramRanges != NULL) {
FreePool (TempSmramRanges);
}

if (Failed) {
return NULL;
}

// MU_CHANGE [END] - CodeQL change

return FullSmramRanges;
}
Expand Down
37 changes: 34 additions & 3 deletions MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,14 @@ IfrToString (
} else {
SrcBuf = GetBufferForValue (&Value);
SrcLen = GetLengthForValue (&Value);
// MU_CHANGE [BEGIN] - CodeQL change
if ((SrcBuf == NULL) || (SrcLen == 0)) {
ASSERT (SrcBuf != NULL);
ASSERT (SrcLen != 0);
return EFI_NOT_FOUND;
}

// MU_CHANGE [END] - CodeQL change
}

TmpBuf = AllocateZeroPool (SrcLen + 3);
Expand All @@ -1183,6 +1191,7 @@ IfrToString (
}

// MU_CHANGE [END] - CodeQL change

if (Format == EFI_IFR_STRING_ASCII) {
CopyMem (TmpBuf, SrcBuf, SrcLen);
PrintFormat = L"%a";
Expand Down Expand Up @@ -1292,7 +1301,8 @@ IfrToUint (
Evaluate opcode EFI_IFR_CATENATE.

@param FormSet Formset which contains this opcode.
@param Result Evaluation result for this opcode.
@param Result Evaluation result for this opcode. Result
will be NULL on a failure.

@retval EFI_SUCCESS Opcode evaluation success.
@retval Other Opcode evaluation failed.
Expand Down Expand Up @@ -1377,10 +1387,24 @@ IfrCatenate (
ASSERT (Result->Buffer != NULL);

TmpBuf = GetBufferForValue (&Value[0]);
ASSERT (TmpBuf != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (TmpBuf == NULL) {
kenlautner marked this conversation as resolved.
Show resolved Hide resolved
ASSERT (TmpBuf != NULL);
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
CopyMem (Result->Buffer, TmpBuf, Length0);
TmpBuf = GetBufferForValue (&Value[1]);
ASSERT (TmpBuf != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (TmpBuf == NULL) {
ASSERT (TmpBuf != NULL);
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
CopyMem (&Result->Buffer[Length0], TmpBuf, Length1);
}

Expand All @@ -1405,6 +1429,13 @@ IfrCatenate (
FreePool (StringPtr);
}

// MU_CHANGE [BEGIN] - CodeQL change
if (EFI_ERROR (Status) && (Result != NULL)) {
FreePool (Result);
}

// MU_CHANGE [END] - CodeQL change

return Status;
}

Expand Down
8 changes: 7 additions & 1 deletion NetworkPkg/Ip4Dxe/Ip4Input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,13 @@ Ip4InstanceDeliverPacket (
// may be not continuous before the data.
//
Head = NetbufAllocSpace (Dup, IP4_MAX_HEADLEN, NET_BUF_HEAD);
ASSERT (Head != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Head == NULL) {
ASSERT (Head != NULL);
return EFI_OUT_OF_RESOURCES;
}

// MU_CHANGE [END] - CodeQL change

Dup->Ip.Ip4 = (IP4_HEAD *)Head;

Expand Down
27 changes: 17 additions & 10 deletions NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,19 +864,26 @@ Ip6ManualAddrDadCallback (
// data with those passed.
//
PassedAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)AllocatePool (Item->DataSize);
ASSERT (PassedAddr != NULL);

Item->Data.Ptr = PassedAddr;
Item->Status = EFI_SUCCESS;

while (!NetMapIsEmpty (&Instance->DadPassedMap)) {
ManualAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)NetMapRemoveHead (&Instance->DadPassedMap, NULL);
CopyMem (PassedAddr, ManualAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));
// MU_CHANGE [BEGIN] - CodeQL change
if (PassedAddr == NULL) {
kenlautner marked this conversation as resolved.
Show resolved Hide resolved
ASSERT (PassedAddr != NULL);
Item->Data.Ptr = NULL;
Item->Status = EFI_OUT_OF_RESOURCES;
} else {
Item->Data.Ptr = PassedAddr;
Item->Status = EFI_SUCCESS;

while (!NetMapIsEmpty (&Instance->DadPassedMap)) {
ManualAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)NetMapRemoveHead (&Instance->DadPassedMap, NULL);
CopyMem (PassedAddr, ManualAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));

PassedAddr++;
}

PassedAddr++;
ASSERT ((UINTN)PassedAddr - (UINTN)Item->Data.Ptr == Item->DataSize);
}

ASSERT ((UINTN)PassedAddr - (UINTN)Item->Data.Ptr == Item->DataSize);
// MU_CHANGE [END] - CodeQL change
}
} else {
//
Expand Down
8 changes: 7 additions & 1 deletion NetworkPkg/Ip6Dxe/Ip6Input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,13 @@ Ip6InstanceDeliverPacket (
// may be not continuous before the data.
//
Head = NetbufAllocSpace (Dup, sizeof (EFI_IP6_HEADER), NET_BUF_HEAD);
ASSERT (Head != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Head == NULL) {
ASSERT (Head != NULL);
return EFI_OUT_OF_RESOURCES;
}

// MU_CHANGE [END] - CodeQL change
Dup->Ip.Ip6 = (EFI_IP6_HEADER *)Head;

CopyMem (Head, Packet->Ip.Ip6, sizeof (EFI_IP6_HEADER));
Expand Down
8 changes: 7 additions & 1 deletion NetworkPkg/Ip6Dxe/Ip6Nd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,13 @@ Ip6SendNeighborSolicit (
IcmpHead->Head.Code = 0;

Target = (EFI_IPv6_ADDRESS *)NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE);
ASSERT (Target != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Target == NULL) {
ASSERT (Target != NULL);
return EFI_OUT_OF_RESOURCES;
}

// MU_CHANGE [END] - CodeQL change
IP6_COPY_ADDRESS (Target, TargetIp6Address);

LinkLayerOption = NULL;
Expand Down
9 changes: 8 additions & 1 deletion NetworkPkg/Ip6Dxe/Ip6Output.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,14 @@ Ip6Output (
// Allocate the space to contain the fragmentable hdrs and copy the data.
//
Buf = NetbufAllocSpace (TmpPacket, FragmentHdrsLen, TRUE);
ASSERT (Buf != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Buf == NULL) {
ASSERT (Buf != NULL);
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}

// MU_CHANGE [END] - CodeQL change
CopyMem (Buf, ExtHdrs + UnFragmentHdrsLen, FragmentHdrsLen);

//
Expand Down
7 changes: 7 additions & 0 deletions NetworkPkg/Library/DxeNetLib/NetBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ NetbufDuplicate (
NetbufReserve (Duplicate, HeadSpace);

Dst = NetbufAllocSpace (Duplicate, Nbuf->TotalSize, NET_BUF_TAIL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Dst == NULL) {
ASSERT (Dst != NULL);
return NULL;
}

// MU_CHANGE [END] - CodeQL change
NetbufCopy (Nbuf, 0, Nbuf->TotalSize, Dst);

return Duplicate;
Expand Down
Loading