Skip to content

Commit

Permalink
NetworkPkg: More CodeQL fixes (#317)
Browse files Browse the repository at this point in the history
## Description

Various fixes

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [x] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Build and boot changes on QemuQ35Pkg to EFI shell.

## Integration Instructions

N/A
  • Loading branch information
TaylorBeebe authored and kenlautner committed Oct 20, 2023
1 parent bb238a2 commit 41e3439
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 43 deletions.
21 changes: 13 additions & 8 deletions NetworkPkg/HttpBootDxe/HttpBootConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,21 @@ HttpBootConfigFormInit (
STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP),
NULL
);
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP),
MenuString,
NULL
);
// MU_CHANGE [BEGIN] - CodeQL change
if (OldMenuString != NULL) {
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP),
MenuString,
NULL
);

FreePool (OldMenuString);
}

// MU_CHANGE [END] - CodeQL change
FreePool (MacString);
FreePool (OldMenuString);

CallbackInfo->Initialized = TRUE;
return EFI_SUCCESS;
Expand Down
38 changes: 22 additions & 16 deletions NetworkPkg/Ip4Dxe/Ip4Config2Nv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,24 +1358,30 @@ Ip4Config2FormInit (
STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP),
NULL
);
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP),
MenuString,
NULL
);

UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP4_DEVICE_FORM_HELP),
PortString,
NULL
);
// MU_CHANGE [BEGIN] - CodeQL change
if (OldMenuString != NULL) {
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP),
MenuString,
NULL
);

UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP4_DEVICE_FORM_HELP),
PortString,
NULL
);

FreePool (OldMenuString);
}

FreePool (MacString);
FreePool (OldMenuString);

// MU_CHANGE [END] - CodeQL change

return EFI_SUCCESS;
}
Expand Down
46 changes: 29 additions & 17 deletions NetworkPkg/Ip6Dxe/Ip6ConfigNv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,16 @@ Ip6FormExtractConfig (
goto Exit;
}

// MU_CHANGE [END] - CodeQL change
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
ConfigRequest = AllocateZeroPool (Size);
ASSERT (ConfigRequest != NULL);

if (ConfigRequest == NULL) {
ASSERT (ConfigRequest != NULL);
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}

// MU_CHANGE [END] - CodeQL change
AllocatedRequest = TRUE;
UnicodeSPrint (
ConfigRequest,
Expand Down Expand Up @@ -2003,23 +2009,29 @@ Ip6ConfigFormInit (
NULL
)
;
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP6_CONFIG_FORM_HELP),
MenuString,
NULL
);
UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP6_DEVICE_FORM_HELP),
PortString,
NULL
);
// MU_CHANGE [BEGIN] - CodeQL change
if (OldMenuString != NULL) {
UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP6_CONFIG_FORM_HELP),
MenuString,
NULL
);
UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
HiiSetString (
CallbackInfo->RegisteredHandle,
STRING_TOKEN (STR_IP6_DEVICE_FORM_HELP),
PortString,
NULL
);

FreePool (OldMenuString);
}

FreePool (MacString);
FreePool (OldMenuString);

// MU_CHANGE [END] - CodeQL change

InitializeListHead (&Instance->Ip6NvData.ManualAddress);
InitializeListHead (&Instance->Ip6NvData.GatewayAddress);
Expand Down
4 changes: 4 additions & 0 deletions NetworkPkg/Ip6Dxe/Ip6Output.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ Ip6SelectInterface (
IP6_INTERFACE *IpIf;
BOOLEAN Exist;

// MU_CHANGE [BEGIN] - CodeQL change
IpIf = NULL;
// MU_CHANGE [END] - CodeQL change

NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ASSERT (Destination != NULL && Source != NULL);

Expand Down
6 changes: 6 additions & 0 deletions NetworkPkg/Library/DxeHttpIoLib/DxeHttpIoLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ HttpIoSendChunkedTransfer (
}

NewHeaders = AllocateZeroPool ((RequestMessage->HeaderCount + AddNewHeader) * sizeof (EFI_HTTP_HEADER));
// MU_CHANGE [BEGIN] - CodeQL change
if (NewHeaders == NULL) {
return EFI_OUT_OF_RESOURCES;
}

// MU_CHANGE [END] - CodeQL change
CopyMem ((VOID *)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
if (AddNewHeader == 0) {
//
Expand Down
8 changes: 7 additions & 1 deletion NetworkPkg/TcpDxe/TcpOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,14 @@ TcpGetSegmentSock (
// copy data to the segment.
//
Data = NetbufAllocSpace (Nbuf, Len, NET_BUF_TAIL);
ASSERT (Data != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Data == NULL) {
ASSERT (Data != NULL);
NetbufFree (Nbuf);
return NULL;
}

// MU_CHANGE [END] - CodeQL change
DataGet = SockGetDataToSend (Tcb->Sk, 0, Len, Data);
}

Expand Down
8 changes: 7 additions & 1 deletion NetworkPkg/VlanConfigDxe/VlanConfigImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ VlanCallback (
// Get Browser data
//
Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));
ASSERT (Configuration != NULL);
// MU_CHANGE [BEGIN] - CodeQL change
if (Configuration == NULL) {
ASSERT (Configuration != NULL);
return EFI_OUT_OF_RESOURCES;
}

// MU_CHANGE [END] - CodeQL change
HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *)Configuration);

VlanConfig = PrivateData->VlanConfig;
Expand Down

0 comments on commit 41e3439

Please sign in to comment.