summaryrefslogtreecommitdiff
path: root/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe
diff options
context:
space:
mode:
authorOliver Smith-Denny <osde@microsoft.com>2026-09-05 01:11:33 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2026-09-08 21:20:17 +0300
commitdd18a85cb698612d9d41edd7845ff060145926de (patch)
treee2c6df259c766c8cd020dcf844b1f1c9cffcea71 /SecurityPkg/VariableAuthenticated/SecureBootConfigDxe
parent75e1de00accacd331fd49c5d45b6726ff9996e12 (diff)
downloadedk2-dd18a85cb698612d9d41edd7845ff060145926de.tar.xz
SecurityPkg: Guard nullable return values
Makes changes to comply with CodeQL unguarded-null-return-dereference alerts. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Diffstat (limited to 'SecurityPkg/VariableAuthenticated/SecureBootConfigDxe')
-rw-r--r--SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c6
-rw-r--r--SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c26
2 files changed, 26 insertions, 6 deletions
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
index 5a23dc517a..65b3f81b6e 100644
--- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
+++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
@@ -98,7 +98,11 @@ ExtractFileNameFromDevicePath (
ASSERT (DevicePath != NULL);
- String = DevicePathToStr (DevicePath);
+ String = DevicePathToStr (DevicePath);
+ if (String == NULL) {
+ return NULL;
+ }
+
MatchString = String;
LastMatch = String;
FileName = NULL;
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
index 1b3b51eea7..95a59c41de 100644
--- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
+++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
@@ -1172,7 +1172,10 @@ CalculateCertHash (
//
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ return FALSE;
+ }
//
// 2. Initialize a hash context.
@@ -1886,7 +1889,10 @@ HashPeImage (
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ goto Done;
+ }
// 1. Load the image header into memory.
@@ -3511,9 +3517,19 @@ SecureBootExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, PrivateData->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequest == NULL) {
+ ASSERT (ConfigRequest != NULL);
+ FreePool (ConfigRequestHdr);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);