@retval EFI_SUCCESS The hexadecimal string is converted into a\r
binary encoded buffer.\r
@retval EFI_INVALID_PARAMETER Invalid hex encoding found in HexStr.\r
+ @retval EFI_BAD_BUFFER_SIZE The length of HexStr is too large for decoding:\r
+ the decoded size cannot be expressed in\r
+ BinLength on output.\r
@retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the\r
converted data.\r
**/\r
IN CHAR8 *HexStr\r
)\r
{\r
+ UINTN BinLengthMin;\r
+ UINT32 BinLengthProvided;\r
UINTN Index;\r
UINTN Length;\r
UINT8 Digit;\r
if (Length == 0 || Length % 2 != 0) {\r
return EFI_INVALID_PARAMETER;\r
}\r
+ //\r
+ // Check if the caller provides enough room for the decoded blob.\r
+ //\r
+ BinLengthMin = Length / 2;\r
+ if (BinLengthMin > MAX_UINT32) {\r
+ return EFI_BAD_BUFFER_SIZE;\r
+ }\r
+ BinLengthProvided = *BinLength;\r
+ *BinLength = (UINT32)BinLengthMin;\r
+ if (BinLengthProvided < BinLengthMin) {\r
+ return EFI_BUFFER_TOO_SMALL;\r
+ }\r
\r
for (Index = 0; Index < Length; Index ++) {\r
TemStr[0] = HexStr[Index];\r
BinBuffer [Index/2] = (UINT8) ((BinBuffer [Index/2] << 4) + Digit);\r
}\r
}\r
-\r
- *BinLength = (UINT32) ((Index + 1)/2);\r
-\r
return EFI_SUCCESS;\r
}\r
\r
@retval EFI_SUCCESS The hexadecimal string is converted into a\r
binary encoded buffer.\r
@retval EFI_INVALID_PARAMETER Invalid hex encoding found in HexStr.\r
+ @retval EFI_BAD_BUFFER_SIZE The length of HexStr is too large for decoding:\r
+ the decoded size cannot be expressed in\r
+ BinLength on output.\r
@retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the\r
converted data.\r
**/\r