From b4b9496b3c17c76fab3ebb5a59d4c8d9b6b5c505 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 6 Aug 2020 12:05:42 -0700 Subject: FmpDevicePkg/FmpDxe: Improve function parameter validation REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2869 Makes some minor improvements to function parameter validation in FmpDxe, in particular to externally exposed functions such as those that back EFI_FIRMWARE_MANAGEMENT_PROTOCOL. Cc: Liming Gao Cc: Michael D Kinney Cc: Guomin Jiang Cc: Wei6 Xu Signed-off-by: Michael Kubacki Reviewed-by: Michael D Kinney Reviewed-by: Guomin Jiang Reviewed-by: Wei6 Xu --- FmpDevicePkg/FmpDxe/FmpDxe.c | 51 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'FmpDevicePkg') diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index a3e3425919..854feec0a1 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -278,6 +278,11 @@ PopulateDescriptor ( EFI_STATUS Status; UINT32 DependenciesSize; + if (Private == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): PopulateDescriptor() - Private is NULL.\n", mImageIdName)); + return; + } + if (Private->DescriptorPopulated) { return; } @@ -451,6 +456,12 @@ GetTheImageInfo ( Status = EFI_SUCCESS; + if (This == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImageInfo() - This is NULL.\n", mImageIdName)); + Status = EFI_INVALID_PARAMETER; + goto cleanup; + } + // // Retrieve the private context structure // @@ -561,6 +572,12 @@ GetTheImage ( Status = EFI_SUCCESS; + if (This == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - This is NULL.\n", mImageIdName)); + Status = EFI_INVALID_PARAMETER; + goto cleanup; + } + // // Retrieve the private context structure // @@ -615,7 +632,8 @@ cleanup: @param[in] Image Pointer to the image. @param[in] ImageSize Size of the image. @param[in] AdditionalHeaderSize Size of any headers that cannot be calculated by this function. - @param[out] PayloadSize + @param[out] PayloadSize An optional pointer to a UINTN that holds the size of the payload + (image size minus headers) @retval !NULL Valid pointer to the header. @retval NULL Structure is bad and pointer cannot be found. @@ -626,7 +644,7 @@ GetFmpHeader ( IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN CONST UINTN ImageSize, IN CONST UINTN AdditionalHeaderSize, - OUT UINTN *PayloadSize + OUT UINTN *PayloadSize OPTIONAL ) { // @@ -640,7 +658,10 @@ GetFmpHeader ( return NULL; } - *PayloadSize = ImageSize - (sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize); + if (PayloadSize != NULL) { + *PayloadSize = ImageSize - (sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize); + } + return (VOID *)((UINT8 *)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize); } @@ -663,6 +684,11 @@ GetAllHeaderSize ( { UINT32 CalculatedSize; + if (Image == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetAllHeaderSize() - Image is NULL.\n", mImageIdName)); + return 0; + } + CalculatedSize = sizeof (Image->MonotonicCount) + AdditionalHeaderSize + Image->AuthInfo.Hdr.dwLength; @@ -743,6 +769,12 @@ CheckTheImage ( return EFI_UNSUPPORTED; } + if (This == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - This is NULL.\n", mImageIdName)); + Status = EFI_INVALID_PARAMETER; + goto cleanup; + } + // // Retrieve the private context structure // @@ -851,7 +883,7 @@ CheckTheImage ( if (ImageIndex != 1) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Index Invalid.\n", mImageIdName)); *ImageUpdatable = IMAGE_UPDATABLE_INVALID_TYPE; - Status = EFI_SUCCESS; + Status = EFI_INVALID_PARAMETER; goto cleanup; } @@ -1026,6 +1058,12 @@ SetTheImage ( return EFI_UNSUPPORTED; } + if (This == NULL) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - This is NULL.\n", mImageIdName)); + Status = EFI_INVALID_PARAMETER; + goto cleanup; + } + // // Retrieve the private context structure // @@ -1382,6 +1420,11 @@ FmpDxeLockEventNotify ( EFI_STATUS Status; FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private; + if (Context == NULL) { + ASSERT (Context != NULL); + return; + } + Private = (FIRMWARE_MANAGEMENT_PRIVATE_DATA *)Context; if (!Private->FmpDeviceLocked) { -- cgit v1.2.3