From 09b794172ec8efcbc00c0ada499e2ef646a10f47 Mon Sep 17 00:00:00 2001 From: lgao4 Date: Tue, 23 Nov 2010 11:13:22 +0000 Subject: [PATCH] Fix the bug that HiiConfigToBlock doesn't update BlockSize when Block is not large enough git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11085 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/HiiDatabaseDxe/ConfigRouting.c | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index 2e73924ca1..4f83fe3866 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -3224,6 +3224,10 @@ Exit: value pair. Block is left updated and Progress points at the '&' preceding the first non-. + @retval EFI_DEVICE_ERROR Block not large enough. Progress undefined. + @retval EFI_NOT_FOUND Target for the specified routing data was not found. + Progress points to the "G" in "GUID" of the errant + routing data. **/ EFI_STATUS @@ -3245,13 +3249,14 @@ HiiConfigToBlock ( UINTN Width; UINT8 *Value; UINTN BufferSize; + UINTN MaxBlockSize; if (This == NULL || BlockSize == NULL || Progress == NULL) { return EFI_INVALID_PARAMETER; } - if (ConfigResp == NULL || Block == NULL) { - *Progress = ConfigResp; + *Progress = ConfigResp; + if (ConfigResp == NULL) { return EFI_INVALID_PARAMETER; } @@ -3261,6 +3266,7 @@ HiiConfigToBlock ( StringPtr = ConfigResp; BufferSize = *BlockSize; Value = NULL; + MaxBlockSize = 0; // // Jump @@ -3366,13 +3372,12 @@ HiiConfigToBlock ( // // Update the Block with configuration info // - - if (Offset + Width > BufferSize) { - return EFI_DEVICE_ERROR; + if ((Block != NULL) && (Offset + Width <= BufferSize)) { + CopyMem (Block + Offset, Value, Width); + } + if (Offset + Width > MaxBlockSize) { + MaxBlockSize = Offset + Width; } - - CopyMem (Block + Offset, Value, Width); - *BlockSize = Offset + Width - 1; FreePool (Value); Value = NULL; @@ -3397,6 +3402,17 @@ HiiConfigToBlock ( } *Progress = StringPtr + StrLen (StringPtr); + *BlockSize = MaxBlockSize - 1; + + if (MaxBlockSize > BufferSize) { + *BlockSize = MaxBlockSize; + if (Block == NULL) { + return EFI_INVALID_PARAMETER; + } else { + return EFI_DEVICE_ERROR; + } + } + return EFI_SUCCESS; Exit: -- 2.39.2