summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library')
-rw-r--r--MdePkg/Library/BaseLib/String.c64
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoff.c6
-rw-r--r--MdePkg/Library/PeiServicesLib/PeiServicesLib.c6
-rw-r--r--MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c482
-rw-r--r--MdePkg/Library/UefiDevicePathLib/DevicePathToText.c6
-rw-r--r--MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c5
-rw-r--r--MdePkg/Library/UefiLib/Acpi.c28
-rw-r--r--MdePkg/Library/UefiLib/Console.c13
-rw-r--r--MdePkg/Library/UefiLib/UefiLibPrint.c30
-rw-r--r--MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c12
10 files changed, 459 insertions, 193 deletions
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index 637c96e7b3..f16e1099be 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -406,10 +406,12 @@ StrDecimalToUintn (
IN CONST CHAR16 *String
)
{
- UINTN Result;
+ UINTN Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result))) {
- return MAX_UINTN;
+ Status = StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -455,10 +457,12 @@ StrDecimalToUint64 (
IN CONST CHAR16 *String
)
{
- UINT64 Result;
+ UINT64 Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result))) {
- return MAX_UINT64;
+ Status = StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -505,10 +509,12 @@ StrHexToUintn (
IN CONST CHAR16 *String
)
{
- UINTN Result;
+ UINTN Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (StrHexToUintnS (String, (CHAR16 **)NULL, &Result))) {
- return MAX_UINTN;
+ Status = StrHexToUintnS (String, (CHAR16 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -555,10 +561,12 @@ StrHexToUint64 (
IN CONST CHAR16 *String
)
{
- UINT64 Result;
+ UINT64 Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (StrHexToUint64S (String, (CHAR16 **)NULL, &Result))) {
- return MAX_UINT64;
+ Status = StrHexToUint64S (String, (CHAR16 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -999,10 +1007,12 @@ AsciiStrDecimalToUintn (
IN CONST CHAR8 *String
)
{
- UINTN Result;
+ UINTN Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result))) {
- return MAX_UINTN;
+ Status = AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -1044,10 +1054,12 @@ AsciiStrDecimalToUint64 (
IN CONST CHAR8 *String
)
{
- UINT64 Result;
+ UINT64 Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result))) {
- return MAX_UINT64;
+ Status = AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -1093,10 +1105,12 @@ AsciiStrHexToUintn (
IN CONST CHAR8 *String
)
{
- UINTN Result;
+ UINTN Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result))) {
- return MAX_UINTN;
+ Status = AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
@@ -1142,10 +1156,12 @@ AsciiStrHexToUint64 (
IN CONST CHAR8 *String
)
{
- UINT64 Result;
+ UINT64 Result;
+ RETURN_STATUS Status;
- if (RETURN_ERROR (AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result))) {
- return MAX_UINT64;
+ Status = AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result);
+ if (Status == RETURN_INVALID_PARAMETER) {
+ Result = 0;
}
return Result;
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 617e86dfda..fab7ab3b4c 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -68,7 +68,7 @@ PeCoffLoaderGetPeHeader (
UINTN Size;
UINTN ReadSize;
UINT32 SectionHeaderOffset;
- UINT32 Index;
+ UINTN Index;
UINT32 HeaderWithoutDataDir;
CHAR8 BufferData;
UINTN NumberOfSections;
@@ -1407,7 +1407,7 @@ PeCoffLoaderLoadImage (
return RETURN_LOAD_ERROR;
}
- if (Section->SizeOfRawData > 0) {
+ if ((Section->SizeOfRawData > 0) && (Base != NULL)) {
Status = ImageContext->ImageRead (
ImageContext->Handle,
Section->PointerToRawData - TeStrippedOffset,
@@ -1424,7 +1424,7 @@ PeCoffLoaderLoadImage (
// If raw size is less then virtual size, zero fill the remaining
//
- if (Size < Section->Misc.VirtualSize) {
+ if ((Size < Section->Misc.VirtualSize) && (Base != NULL)) {
ZeroMem (Base + Size, Section->Misc.VirtualSize - Size);
}
diff --git a/MdePkg/Library/PeiServicesLib/PeiServicesLib.c b/MdePkg/Library/PeiServicesLib/PeiServicesLib.c
index 98cc69c3a2..16d5134981 100644
--- a/MdePkg/Library/PeiServicesLib/PeiServicesLib.c
+++ b/MdePkg/Library/PeiServicesLib/PeiServicesLib.c
@@ -685,7 +685,11 @@ InternalPeiServicesInstallFvInfoPpi (
}
FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
- ASSERT (FvInfoPpiDescriptor != NULL);
+ if (FvInfoPpiDescriptor == NULL) {
+ ASSERT (FvInfoPpiDescriptor != NULL);
+ // Need to return here, FV may not be published, but we are out of resources anyway...
+ return;
+ }
FvInfoPpiDescriptor->Guid = PpiGuid;
FvInfoPpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index 86ecb66ba3..27668eee30 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -269,14 +269,14 @@ IsHexStr (
//
// skip preceeding white space
//
- while ((*Str != 0) && *Str == L' ') {
+ while (*Str == L' ') {
Str++;
}
//
// skip preceeding zeros
//
- while ((*Str != 0) && *Str == L'0') {
+ while (*Str == L'0') {
Str++;
}
@@ -388,7 +388,10 @@ DevPathFromTextGenericPath (
(UINT16)(sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)
);
- StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength);
+ if (Node != NULL) {
+ StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength);
+ }
+
return Node;
}
@@ -453,8 +456,10 @@ DevPathFromTextPci (
(UINT16)sizeof (PCI_DEVICE_PATH)
);
- Pci->Function = (UINT8)Strtoi (FunctionStr);
- Pci->Device = (UINT8)Strtoi (DeviceStr);
+ if (Pci != NULL) {
+ Pci->Function = (UINT8)Strtoi (FunctionStr);
+ Pci->Device = (UINT8)Strtoi (DeviceStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Pci;
}
@@ -482,7 +487,9 @@ DevPathFromTextPcCard (
(UINT16)sizeof (PCCARD_DEVICE_PATH)
);
- Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr);
+ if (Pccard != NULL) {
+ Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Pccard;
}
@@ -514,9 +521,11 @@ DevPathFromTextMemoryMapped (
(UINT16)sizeof (MEMMAP_DEVICE_PATH)
);
- MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr);
- Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
- Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
+ if (MemMap != NULL) {
+ MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr);
+ Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
+ Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)MemMap;
}
@@ -559,8 +568,10 @@ ConvertFromTextVendor (
(UINT16)(sizeof (VENDOR_DEVICE_PATH) + Length)
);
- StrToGuid (GuidStr, &Vendor->Guid);
- StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length);
+ if (Vendor != NULL) {
+ StrToGuid (GuidStr, &Vendor->Guid);
+ StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
}
@@ -607,7 +618,10 @@ DevPathFromTextCtrl (
HW_CONTROLLER_DP,
(UINT16)sizeof (CONTROLLER_DEVICE_PATH)
);
- Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr);
+
+ if (Controller != NULL) {
+ Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Controller;
}
@@ -637,11 +651,13 @@ DevPathFromTextBmc (
(UINT16)sizeof (BMC_DEVICE_PATH)
);
- BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr);
- WriteUnaligned64 (
- (UINT64 *)(&BmcDp->BaseAddress),
- StrHexToUint64 (BaseAddressStr)
- );
+ if (BmcDp != NULL) {
+ BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr);
+ WriteUnaligned64 (
+ (UINT64 *)(&BmcDp->BaseAddress),
+ StrHexToUint64 (BaseAddressStr)
+ );
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)BmcDp;
}
@@ -706,8 +722,10 @@ DevPathFromTextAcpi (
(UINT16)sizeof (ACPI_HID_DEVICE_PATH)
);
- Acpi->HID = EisaIdFromText (HIDStr);
- Acpi->UID = (UINT32)Strtoi (UIDStr);
+ if (Acpi != NULL) {
+ Acpi->HID = EisaIdFromText (HIDStr);
+ Acpi->UID = (UINT32)Strtoi (UIDStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
}
@@ -737,8 +755,10 @@ ConvertFromTextAcpi (
(UINT16)sizeof (ACPI_HID_DEVICE_PATH)
);
- Acpi->HID = EFI_PNP_ID (PnPId);
- Acpi->UID = (UINT32)Strtoi (UIDStr);
+ if (Acpi != NULL) {
+ Acpi->HID = EFI_PNP_ID (PnPId);
+ Acpi->UID = (UINT32)Strtoi (UIDStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
}
@@ -878,14 +898,16 @@ DevPathFromTextAcpiEx (
Length
);
- AcpiEx->HID = EisaIdFromText (HIDStr);
- AcpiEx->CID = EisaIdFromText (CIDStr);
- AcpiEx->UID = (UINT32)Strtoi (UIDStr);
+ if (AcpiEx != NULL) {
+ AcpiEx->HID = EisaIdFromText (HIDStr);
+ AcpiEx->CID = EisaIdFromText (CIDStr);
+ AcpiEx->UID = (UINT32)Strtoi (UIDStr);
- AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
- StrToAscii (HIDSTRStr, &AsciiStr);
- StrToAscii (UIDSTRStr, &AsciiStr);
- StrToAscii (CIDSTRStr, &AsciiStr);
+ AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
+ StrToAscii (HIDSTRStr, &AsciiStr);
+ StrToAscii (UIDSTRStr, &AsciiStr);
+ StrToAscii (CIDSTRStr, &AsciiStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
}
@@ -920,6 +942,10 @@ DevPathFromTextAcpiExp (
Length
);
+ if (AcpiEx == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
+ }
+
AcpiEx->HID = EisaIdFromText (HIDStr);
//
// According to UEFI spec, the CID parameter is optional and has a default value of 0.
@@ -975,7 +1001,10 @@ DevPathFromTextAcpiAdr (
ACPI_ADR_DP,
(UINT16)sizeof (ACPI_ADR_DEVICE_PATH)
);
- ASSERT (AcpiAdr != NULL);
+ if (AcpiAdr == NULL) {
+ ASSERT (AcpiAdr != NULL);
+ return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr;
+ }
for (Index = 0; ; Index++) {
DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
@@ -990,7 +1019,12 @@ DevPathFromTextAcpiAdr (
Length + sizeof (UINT32),
AcpiAdr
);
- ASSERT (AcpiAdr != NULL);
+
+ if (AcpiAdr == NULL) {
+ ASSERT (AcpiAdr != NULL);
+ return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr;
+ }
+
SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
}
@@ -1040,6 +1074,10 @@ DevPathFromTextAta (
(UINT16)sizeof (ATAPI_DEVICE_PATH)
);
+ if (Atapi == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)Atapi;
+ }
+
PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
LunStr = GetNextParamStr (&TextDeviceNode);
@@ -1090,8 +1128,10 @@ DevPathFromTextScsi (
(UINT16)sizeof (SCSI_DEVICE_PATH)
);
- Scsi->Pun = (UINT16)Strtoi (PunStr);
- Scsi->Lun = (UINT16)Strtoi (LunStr);
+ if (Scsi != NULL) {
+ Scsi->Pun = (UINT16)Strtoi (PunStr);
+ Scsi->Lun = (UINT16)Strtoi (LunStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Scsi;
}
@@ -1121,9 +1161,11 @@ DevPathFromTextFibre (
(UINT16)sizeof (FIBRECHANNEL_DEVICE_PATH)
);
- Fibre->Reserved = 0;
- Strtoi64 (WWNStr, &Fibre->WWN);
- Strtoi64 (LunStr, &Fibre->Lun);
+ if (Fibre != NULL) {
+ Fibre->Reserved = 0;
+ Strtoi64 (WWNStr, &Fibre->WWN);
+ Strtoi64 (LunStr, &Fibre->Lun);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Fibre;
}
@@ -1153,12 +1195,14 @@ DevPathFromTextFibreEx (
(UINT16)sizeof (FIBRECHANNELEX_DEVICE_PATH)
);
- FibreEx->Reserved = 0;
- Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN));
- Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun));
+ if (FibreEx != NULL) {
+ FibreEx->Reserved = 0;
+ Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN));
+ Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun));
- *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN));
- *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun));
+ *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN));
+ *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun));
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)FibreEx;
}
@@ -1186,8 +1230,10 @@ DevPathFromText1394 (
(UINT16)sizeof (F1394_DEVICE_PATH)
);
- F1394DevPath->Reserved = 0;
- F1394DevPath->Guid = StrHexToUint64 (GuidStr);
+ if (F1394DevPath != NULL) {
+ F1394DevPath->Reserved = 0;
+ F1394DevPath->Guid = StrHexToUint64 (GuidStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)F1394DevPath;
}
@@ -1217,8 +1263,10 @@ DevPathFromTextUsb (
(UINT16)sizeof (USB_DEVICE_PATH)
);
- Usb->ParentPortNumber = (UINT8)Strtoi (PortStr);
- Usb->InterfaceNumber = (UINT8)Strtoi (InterfaceStr);
+ if (Usb != NULL) {
+ Usb->ParentPortNumber = (UINT8)Strtoi (PortStr);
+ Usb->InterfaceNumber = (UINT8)Strtoi (InterfaceStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Usb;
}
@@ -1246,7 +1294,9 @@ DevPathFromTextI2O (
(UINT16)sizeof (I2O_DEVICE_PATH)
);
- I2ODevPath->Tid = (UINT32)Strtoi (TIDStr);
+ if (I2ODevPath != NULL) {
+ I2ODevPath->Tid = (UINT32)Strtoi (TIDStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)I2ODevPath;
}
@@ -1282,11 +1332,13 @@ DevPathFromTextInfiniband (
(UINT16)sizeof (INFINIBAND_DEVICE_PATH)
);
- InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr);
- StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid);
- Strtoi64 (SidStr, &InfiniBand->ServiceId);
- Strtoi64 (TidStr, &InfiniBand->TargetPortId);
- Strtoi64 (DidStr, &InfiniBand->DeviceId);
+ if (InfiniBand != NULL) {
+ InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr);
+ StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid);
+ Strtoi64 (SidStr, &InfiniBand->ServiceId);
+ Strtoi64 (TidStr, &InfiniBand->TargetPortId);
+ Strtoi64 (DidStr, &InfiniBand->DeviceId);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)InfiniBand;
}
@@ -1331,7 +1383,10 @@ DevPathFromTextVenPcAnsi (
MSG_VENDOR_DP,
(UINT16)sizeof (VENDOR_DEVICE_PATH)
);
- CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
+
+ if (Vendor != NULL) {
+ CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
}
@@ -1356,7 +1411,10 @@ DevPathFromTextVenVt100 (
MSG_VENDOR_DP,
(UINT16)sizeof (VENDOR_DEVICE_PATH)
);
- CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
+
+ if (Vendor != NULL) {
+ CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
}
@@ -1381,7 +1439,10 @@ DevPathFromTextVenVt100Plus (
MSG_VENDOR_DP,
(UINT16)sizeof (VENDOR_DEVICE_PATH)
);
- CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
+
+ if (Vendor != NULL) {
+ CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
}
@@ -1406,7 +1467,10 @@ DevPathFromTextVenUtf8 (
MSG_VENDOR_DP,
(UINT16)sizeof (VENDOR_DEVICE_PATH)
);
- CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
+
+ if (Vendor != NULL) {
+ CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
}
@@ -1434,13 +1498,15 @@ DevPathFromTextUartFlowCtrl (
(UINT16)sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
);
- CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
- if (StrCmp (ValueStr, L"XonXoff") == 0) {
- UartFlowControl->FlowControlMap = 2;
- } else if (StrCmp (ValueStr, L"Hardware") == 0) {
- UartFlowControl->FlowControlMap = 1;
- } else {
- UartFlowControl->FlowControlMap = 0;
+ if (UartFlowControl != NULL) {
+ CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
+ if (StrCmp (ValueStr, L"XonXoff") == 0) {
+ UartFlowControl->FlowControlMap = 2;
+ } else if (StrCmp (ValueStr, L"Hardware") == 0) {
+ UartFlowControl->FlowControlMap = 1;
+ } else {
+ UartFlowControl->FlowControlMap = 0;
+ }
}
return (EFI_DEVICE_PATH_PROTOCOL *)UartFlowControl;
@@ -1485,6 +1551,10 @@ DevPathFromTextSAS (
(UINT16)sizeof (SAS_DEVICE_PATH)
);
+ if (Sas == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)Sas;
+ }
+
CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
Strtoi64 (AddressStr, &Sas->SasAddress);
Strtoi64 (LunStr, &Sas->Lun);
@@ -1580,6 +1650,10 @@ DevPathFromTextSasEx (
(UINT16)sizeof (SASEX_DEVICE_PATH)
);
+ if (SasEx == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)SasEx;
+ }
+
Strtoi64 (AddressStr, &SasAddress);
Strtoi64 (LunStr, &Lun);
WriteUnaligned64 ((UINT64 *)&SasEx->SasAddress, SwapBytes64 (SasAddress));
@@ -1663,12 +1737,14 @@ DevPathFromTextNVMe (
(UINT16)sizeof (NVME_NAMESPACE_DEVICE_PATH)
);
- Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr);
- Uuid = (UINT8 *)&Nvme->NamespaceUuid;
+ if (Nvme != NULL) {
+ Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr);
+ Uuid = (UINT8 *)&Nvme->NamespaceUuid;
- Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
- while (Index-- != 0) {
- Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
+ Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
+ while (Index-- != 0) {
+ Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
+ }
}
return (EFI_DEVICE_PATH_PROTOCOL *)Nvme;
@@ -1699,8 +1775,10 @@ DevPathFromTextUfs (
(UINT16)sizeof (UFS_DEVICE_PATH)
);
- Ufs->Pun = (UINT8)Strtoi (PunStr);
- Ufs->Lun = (UINT8)Strtoi (LunStr);
+ if (Ufs != NULL) {
+ Ufs->Pun = (UINT8)Strtoi (PunStr);
+ Ufs->Lun = (UINT8)Strtoi (LunStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Ufs;
}
@@ -1728,7 +1806,9 @@ DevPathFromTextSd (
(UINT16)sizeof (SD_DEVICE_PATH)
);
- Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
+ if (Sd != NULL) {
+ Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Sd;
}
@@ -1756,7 +1836,9 @@ DevPathFromTextEmmc (
(UINT16)sizeof (EMMC_DEVICE_PATH)
);
- Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
+ if (Emmc != NULL) {
+ Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Emmc;
}
@@ -1782,7 +1864,9 @@ DevPathFromTextDebugPort (
(UINT16)sizeof (VENDOR_DEVICE_PATH)
);
- CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
+ if (Vend != NULL) {
+ CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vend;
}
@@ -1813,14 +1897,16 @@ DevPathFromTextMAC (
(UINT16)sizeof (MAC_ADDR_DEVICE_PATH)
);
- MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr);
+ if (MACDevPath != NULL) {
+ MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr);
- Length = sizeof (EFI_MAC_ADDRESS);
- if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) {
- Length = 6;
- }
+ Length = sizeof (EFI_MAC_ADDRESS);
+ if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) {
+ Length = 6;
+ }
- StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
+ StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)MACDevPath;
}
@@ -1882,6 +1968,10 @@ DevPathFromTextIPv4 (
(UINT16)sizeof (IPv4_DEVICE_PATH)
);
+ if (IPv4 == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)IPv4;
+ }
+
StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);
IPv4->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
if (StrCmp (TypeStr, L"Static") == 0) {
@@ -1938,6 +2028,10 @@ DevPathFromTextIPv6 (
(UINT16)sizeof (IPv6_DEVICE_PATH)
);
+ if (IPv6 == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)IPv6;
+ }
+
StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);
IPv6->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
if (StrCmp (TypeStr, L"Static") == 0) {
@@ -1992,6 +2086,10 @@ DevPathFromTextUart (
(UINT16)sizeof (UART_DEVICE_PATH)
);
+ if (Uart == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)Uart;
+ }
+
if (StrCmp (BaudStr, L"DEFAULT") == 0) {
Uart->BaudRate = 115200;
} else {
@@ -2072,6 +2170,10 @@ ConvertFromTextUsbClass (
(UINT16)sizeof (USB_CLASS_DEVICE_PATH)
);
+ if (UsbClass == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)UsbClass;
+ }
+
VIDStr = GetNextParamStr (&TextDeviceNode);
PIDStr = GetNextParamStr (&TextDeviceNode);
if (UsbClassText->ClassExist) {
@@ -2513,19 +2615,22 @@ DevPathFromTextUsbWwid (
MSG_USB_WWID_DP,
(UINT16)(sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
);
- UsbWwid->VendorId = (UINT16)Strtoi (VIDStr);
- UsbWwid->ProductId = (UINT16)Strtoi (PIDStr);
- UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr);
- //
- // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
- // Therefore, the '\0' will not be copied.
- //
- CopyMem (
- (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
- SerialNumberStr,
- SerialNumberStrLen * sizeof (CHAR16)
- );
+ if (UsbWwid != NULL) {
+ UsbWwid->VendorId = (UINT16)Strtoi (VIDStr);
+ UsbWwid->ProductId = (UINT16)Strtoi (PIDStr);
+ UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr);
+
+ //
+ // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
+ // Therefore, the '\0' will not be copied.
+ //
+ CopyMem (
+ (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
+ SerialNumberStr,
+ SerialNumberStrLen * sizeof (CHAR16)
+ );
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)UsbWwid;
}
@@ -2553,7 +2658,9 @@ DevPathFromTextUnit (
(UINT16)sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
);
- LogicalUnit->Lun = (UINT8)Strtoi (LunStr);
+ if (LogicalUnit != NULL) {
+ LogicalUnit->Lun = (UINT8)Strtoi (LunStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)LogicalUnit;
}
@@ -2596,6 +2703,10 @@ DevPathFromTextiSCSI (
(UINT16)(sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
);
+ if (ISCSIDevPath == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)ISCSIDevPath;
+ }
+
AsciiStr = ISCSIDevPath->TargetName;
StrToAscii (NameStr, &AsciiStr);
@@ -2657,7 +2768,9 @@ DevPathFromTextVlan (
(UINT16)sizeof (VLAN_DEVICE_PATH)
);
- Vlan->VlanId = (UINT16)Strtoi (VlanStr);
+ if (Vlan != NULL) {
+ Vlan->VlanId = (UINT16)Strtoi (VlanStr);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Vlan;
}
@@ -2684,12 +2797,16 @@ DevPathFromTextBluetooth (
MSG_BLUETOOTH_DP,
(UINT16)sizeof (BLUETOOTH_DEVICE_PATH)
);
- StrHexToBytes (
- BluetoothStr,
- sizeof (BLUETOOTH_ADDRESS) * 2,
- BluetoothDp->BD_ADDR.Address,
- sizeof (BLUETOOTH_ADDRESS)
- );
+
+ if (BluetoothDp != NULL) {
+ StrHexToBytes (
+ BluetoothStr,
+ sizeof (BLUETOOTH_ADDRESS) * 2,
+ BluetoothDp->BD_ADDR.Address,
+ sizeof (BLUETOOTH_ADDRESS)
+ );
+ }
+
return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothDp;
}
@@ -2718,7 +2835,7 @@ DevPathFromTextWiFi (
(UINT16)sizeof (WIFI_DEVICE_PATH)
);
- if (NULL != SSIdStr) {
+ if ((NULL != SSIdStr) && (NULL != WiFiDp)) {
DataLen = StrLen (SSIdStr);
if (StrLen (SSIdStr) > 32) {
SSIdStr[32] = L'\0';
@@ -2757,13 +2874,16 @@ DevPathFromTextBluetoothLE (
(UINT16)sizeof (BLUETOOTH_LE_DEVICE_PATH)
);
- BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr);
- StrHexToBytes (
- BluetoothLeAddrStr,
- sizeof (BluetoothLeDp->Address.Address) * 2,
- BluetoothLeDp->Address.Address,
- sizeof (BluetoothLeDp->Address.Address)
- );
+ if (BluetoothLeDp != NULL) {
+ BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr);
+ StrHexToBytes (
+ BluetoothLeAddrStr,
+ sizeof (BluetoothLeDp->Address.Address) * 2,
+ BluetoothLeDp->Address.Address,
+ sizeof (BluetoothLeDp->Address.Address)
+ );
+ }
+
return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothLeDp;
}
@@ -2883,7 +3003,7 @@ DevPathFromTextUri (
(UINT16)(sizeof (URI_DEVICE_PATH) + UriLength)
);
- while (UriLength-- != 0) {
+ while (Uri != NULL && UriLength-- != 0) {
Uri->Uri[UriLength] = (CHAR8)UriStr[UriLength];
}
@@ -2938,6 +3058,10 @@ DevPathFromTextHD (
(UINT16)sizeof (HARDDRIVE_DEVICE_PATH)
);
+ if (Hd == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)Hd;
+ }
+
Hd->PartitionNumber = (UINT32)Strtoi (PartitionStr);
ZeroMem (Hd->Signature, 16);
@@ -2991,9 +3115,11 @@ DevPathFromTextCDROM (
(UINT16)sizeof (CDROM_DEVICE_PATH)
);
- CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr);
- Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
- Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
+ if (CDROMDevPath != NULL) {
+ CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr);
+ Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
+ Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)CDROMDevPath;
}
@@ -3039,7 +3165,9 @@ DevPathFromTextFilePath (
(UINT16)(sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
);
- StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
+ if (File != NULL) {
+ StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)File;
}
@@ -3067,7 +3195,9 @@ DevPathFromTextMedia (
(UINT16)sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
);
- StrToGuid (GuidStr, &Media->Protocol);
+ if (Media != NULL) {
+ StrToGuid (GuidStr, &Media->Protocol);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Media;
}
@@ -3095,7 +3225,9 @@ DevPathFromTextFv (
(UINT16)sizeof (MEDIA_FW_VOL_DEVICE_PATH)
);
- StrToGuid (GuidStr, &Fv->FvName);
+ if (Fv != NULL) {
+ StrToGuid (GuidStr, &Fv->FvName);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Fv;
}
@@ -3123,7 +3255,9 @@ DevPathFromTextFvFile (
(UINT16)sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
);
- StrToGuid (GuidStr, &FvFile->FvFileName);
+ if (FvFile != NULL) {
+ StrToGuid (GuidStr, &FvFile->FvFileName);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)FvFile;
}
@@ -3153,8 +3287,10 @@ DevPathFromTextRelativeOffsetRange (
(UINT16)sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
);
- Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
- Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
+ if (Offset != NULL) {
+ Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
+ Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)Offset;
}
@@ -3190,12 +3326,14 @@ DevPathFromTextRamDisk (
(UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
);
- Strtoi64 (StartingAddrStr, &StartingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
- Strtoi64 (EndingAddrStr, &EndingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
- RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
- StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
+ if (RamDisk != NULL) {
+ Strtoi64 (StartingAddrStr, &StartingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
+ Strtoi64 (EndingAddrStr, &EndingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
+ RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
+ StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
}
@@ -3230,12 +3368,14 @@ DevPathFromTextVirtualDisk (
(UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
);
- Strtoi64 (StartingAddrStr, &StartingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
- Strtoi64 (EndingAddrStr, &EndingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
- RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
- CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
+ if (RamDisk != NULL) {
+ Strtoi64 (StartingAddrStr, &StartingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
+ Strtoi64 (EndingAddrStr, &EndingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
+ RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
+ CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
}
@@ -3270,12 +3410,14 @@ DevPathFromTextVirtualCd (
(UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
);
- Strtoi64 (StartingAddrStr, &StartingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
- Strtoi64 (EndingAddrStr, &EndingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
- RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
- CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
+ if (RamDisk != NULL) {
+ Strtoi64 (StartingAddrStr, &StartingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
+ Strtoi64 (EndingAddrStr, &EndingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
+ RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
+ CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
}
@@ -3310,12 +3452,14 @@ DevPathFromTextPersistentVirtualDisk (
(UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
);
- Strtoi64 (StartingAddrStr, &StartingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
- Strtoi64 (EndingAddrStr, &EndingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
- RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
- CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
+ if (RamDisk != NULL) {
+ Strtoi64 (StartingAddrStr, &StartingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
+ Strtoi64 (EndingAddrStr, &EndingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
+ RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
+ CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
}
@@ -3350,12 +3494,14 @@ DevPathFromTextPersistentVirtualCd (
(UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
);
- Strtoi64 (StartingAddrStr, &StartingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
- Strtoi64 (EndingAddrStr, &EndingAddr);
- WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
- RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
- CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
+ if (RamDisk != NULL) {
+ Strtoi64 (StartingAddrStr, &StartingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
+ Strtoi64 (EndingAddrStr, &EndingAddr);
+ WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
+ RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
+ CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
+ }
return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
}
@@ -3404,6 +3550,10 @@ DevPathFromTextBBS (
(UINT16)(sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
);
+ if (Bbs == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)Bbs;
+ }
+
if (StrCmp (TypeStr, L"Floppy") == 0) {
Bbs->DeviceType = BBS_TYPE_FLOPPY;
} else if (StrCmp (TypeStr, L"HD") == 0) {
@@ -3455,6 +3605,11 @@ DevPathFromTextSata (
MSG_SATA_DP,
(UINT16)sizeof (SATA_DEVICE_PATH)
);
+
+ if (Sata == NULL) {
+ return (EFI_DEVICE_PATH_PROTOCOL *)Sata;
+ }
+
Sata->HBAPortNumber = (UINT16)Strtoi (Param1);
//
@@ -3652,29 +3807,54 @@ UefiDevicePathLibConvertTextToDevicePath (
}
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
- ASSERT (DevicePath != NULL);
+
+ if (DevicePath == NULL) {
+ ASSERT (DevicePath != NULL);
+ return NULL;
+ }
+
SetDevicePathEndNode (DevicePath);
DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
+ if (DevicePathStr == NULL) {
+ return NULL;
+ }
+
Str = DevicePathStr;
while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
- FreePool (DevicePath);
- FreePool (DeviceNode);
+ if (DevicePath != NULL) {
+ FreePool (DevicePath);
+ }
+
+ if (DeviceNode != NULL) {
+ FreePool (DeviceNode);
+ }
+
DevicePath = NewDevicePath;
if (IsInstanceEnd) {
DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
- ASSERT (DeviceNode != NULL);
+ if (DeviceNode == NULL) {
+ ASSERT (DeviceNode != NULL);
+ return NULL;
+ }
+
SetDevicePathEndNode (DeviceNode);
DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
- FreePool (DevicePath);
- FreePool (DeviceNode);
+ if (DevicePath != NULL) {
+ FreePool (DevicePath);
+ }
+
+ if (DeviceNode != NULL) {
+ FreePool (DeviceNode);
+ }
+
DevicePath = NewDevicePath;
}
}
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
index afbd590787..e827daed5a 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
@@ -1842,7 +1842,11 @@ DevPathToTextUri (
Uri = DevPath;
UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH);
UriStr = AllocatePool (UriLength + 1);
- ASSERT (UriStr != NULL);
+
+ if (UriStr == NULL) {
+ ASSERT (UriStr != NULL);
+ return;
+ }
CopyMem (UriStr, Uri->Uri, UriLength);
UriStr[UriLength] = '\0';
diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
index 86678e965d..642b754d64 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -930,6 +930,11 @@ FileHandleReturnLine (
Status = FileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
if (Status == EFI_BUFFER_TOO_SMALL) {
RetVal = AllocateZeroPool (Size);
+
+ if (RetVal == NULL) {
+ return NULL;
+ }
+
Status = FileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
}
diff --git a/MdePkg/Library/UefiLib/Acpi.c b/MdePkg/Library/UefiLib/Acpi.c
index 397fde24ed..983d3774c3 100644
--- a/MdePkg/Library/UefiLib/Acpi.c
+++ b/MdePkg/Library/UefiLib/Acpi.c
@@ -220,7 +220,12 @@ LocateAcpiTableInAcpiConfigurationTable (
NULL,
NULL
);
- Table = LocateAcpiDsdtFromFadt (Fadt);
+
+ if (Fadt != NULL) {
+ Table = LocateAcpiDsdtFromFadt (Fadt);
+ } else {
+ Table = NULL;
+ }
} else if (Signature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
ASSERT (PreviousTable == NULL);
//
@@ -234,7 +239,12 @@ LocateAcpiTableInAcpiConfigurationTable (
NULL,
NULL
);
- Table = LocateAcpiFacsFromFadt (Fadt);
+
+ if (Fadt != NULL) {
+ Table = LocateAcpiFacsFromFadt (Fadt);
+ } else {
+ Table = NULL;
+ }
} else {
Table = ScanTableInSDT (
Xsdt,
@@ -275,7 +285,12 @@ LocateAcpiTableInAcpiConfigurationTable (
NULL,
NULL
);
- Table = LocateAcpiDsdtFromFadt (Fadt);
+
+ if (Fadt != NULL) {
+ Table = LocateAcpiDsdtFromFadt (Fadt);
+ } else {
+ Table = NULL;
+ }
} else if (Signature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
ASSERT (PreviousTable == NULL);
//
@@ -289,7 +304,12 @@ LocateAcpiTableInAcpiConfigurationTable (
NULL,
NULL
);
- Table = LocateAcpiFacsFromFadt (Fadt);
+
+ if (Fadt != NULL) {
+ Table = LocateAcpiFacsFromFadt (Fadt);
+ } else {
+ Table = NULL;
+ }
} else {
Table = ScanTableInSDT (
Rsdt,
diff --git a/MdePkg/Library/UefiLib/Console.c b/MdePkg/Library/UefiLib/Console.c
index c37e3d0f58..fc18131680 100644
--- a/MdePkg/Library/UefiLib/Console.c
+++ b/MdePkg/Library/UefiLib/Console.c
@@ -477,7 +477,11 @@ CreatePopUp (
// Allocate a buffer for a single line of the popup with borders and a Null-terminator
//
Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));
- ASSERT (Line != NULL);
+
+ if (Line == NULL) {
+ ASSERT (Line != NULL);
+ return;
+ }
//
// Draw top of popup box
@@ -513,7 +517,12 @@ CreatePopUp (
//
UefiLibGetStringWidth (String, TRUE, MaxLength, &Length);
TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
- ASSERT (TmpString != NULL);
+
+ if (TmpString == NULL) {
+ ASSERT (TmpString != NULL);
+ break;
+ }
+
StrnCpyS (TmpString, Length + 1, String, Length - 3);
StrCatS (TmpString, Length + 1, L"...");
diff --git a/MdePkg/Library/UefiLib/UefiLibPrint.c b/MdePkg/Library/UefiLib/UefiLibPrint.c
index 39edeb7283..c2c6cacd55 100644
--- a/MdePkg/Library/UefiLib/UefiLibPrint.c
+++ b/MdePkg/Library/UefiLib/UefiLibPrint.c
@@ -65,7 +65,11 @@ InternalPrint (
BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
Buffer = (CHAR16 *)AllocatePool (BufferSize);
- ASSERT (Buffer != NULL);
+
+ if (Buffer == NULL) {
+ ASSERT (Buffer != NULL);
+ return 0;
+ }
Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
@@ -199,7 +203,11 @@ AsciiInternalPrint (
BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
Buffer = (CHAR16 *)AllocatePool (BufferSize);
- ASSERT (Buffer != NULL);
+
+ if (Buffer == NULL) {
+ ASSERT (Buffer != NULL);
+ return 0;
+ }
Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
@@ -419,7 +427,11 @@ InternalPrintGraphic (
}
Blt = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
- ASSERT (Blt != NULL);
+
+ if (Blt == NULL) {
+ ASSERT (Blt != NULL);
+ goto Error;
+ }
Blt->Width = (UINT16)(HorizontalResolution);
Blt->Height = (UINT16)(VerticalResolution);
@@ -625,7 +637,11 @@ PrintXY (
BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
Buffer = (CHAR16 *)AllocatePool (BufferSize);
- ASSERT (Buffer != NULL);
+
+ if (Buffer == NULL) {
+ ASSERT (Buffer != NULL);
+ return 0;
+ }
PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
@@ -703,7 +719,11 @@ AsciiPrintXY (
BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
Buffer = (CHAR16 *)AllocatePool (BufferSize);
- ASSERT (Buffer != NULL);
+
+ if (Buffer == NULL) {
+ ASSERT (Buffer != NULL);
+ return 0;
+ }
PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
diff --git a/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c b/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c
index c7988367cf..6f4677bd27 100644
--- a/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c
+++ b/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c
@@ -184,7 +184,11 @@ DxePciSegmentLibPciRootBridgeIoReadWorker (
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address);
- ASSERT (PciRootBridgeIo != NULL);
+
+ if (PciRootBridgeIo == NULL) {
+ ASSERT (PciRootBridgeIo != NULL);
+ return 0;
+ }
PciRootBridgeIo->Pci.Read (
PciRootBridgeIo,
@@ -223,7 +227,11 @@ DxePciSegmentLibPciRootBridgeIoWriteWorker (
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address);
- ASSERT (PciRootBridgeIo != NULL);
+
+ if (PciRootBridgeIo == NULL) {
+ ASSERT (PciRootBridgeIo != NULL);
+ return 0;
+ }
PciRootBridgeIo->Pci.Write (
PciRootBridgeIo,