ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()

Modify the signature of the DumpGasStruct() function to include the
buffer length parameter and to return the number of bytes parsed by
the function.

This way it becomes possible to prevent buffer overruns when dumping
Generic Address Structure's (GAS) fields in the acpiview table
parsers.

Update all existing DumpGasStruct() calls in acpiview to add the
length argument.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
This commit is contained in:
Krzysztof Koch 2019-07-22 15:50:21 -07:00 committed by Jaben Carsey
parent d21e5dbbbf
commit 58cc0ffe68
3 changed files with 22 additions and 14 deletions

View File

@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Indent Number of spaces to indent the output.
@param [in] Length Length of the GAS structure buffer.
@retval Number of bytes parsed.
**/
VOID
UINT32
EFIAPI
DumpGasStruct (
IN UINT8* Ptr,
IN UINT32 Indent
IN UINT32 Indent,
IN UINT32 Length
)
{
Print (L"\n");
ParseAcpi (
TRUE,
Indent,
NULL,
Ptr,
GAS_LENGTH,
PARSER_PARAMS (GasParser)
);
return ParseAcpi (
TRUE,
Indent,
NULL,
Ptr,
Length,
PARSER_PARAMS (GasParser)
);
}
/**
@ -621,7 +625,7 @@ DumpGas (
IN UINT8* Ptr
)
{
DumpGasStruct (Ptr, 2);
DumpGasStruct (Ptr, 2, GAS_LENGTH);
}
/**

View File

@ -405,12 +405,16 @@ ParseAcpi (
@param [in] Ptr Pointer to the start of the buffer.
@param [in] Indent Number of spaces to indent the output.
@param [in] Length Length of the GAS structure buffer.
@retval Number of bytes parsed.
**/
VOID
UINT32
EFIAPI
DumpGasStruct (
IN UINT8* Ptr,
IN UINT32 Indent
IN UINT32 Indent,
IN UINT32 Length
);
/**

View File

@ -134,7 +134,7 @@ DumpDbgDeviceInfo (
AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
while (Index < (*GasCount)) {
PrintFieldName (4, L"BaseAddressRegister");
DumpGasStruct (DataPtr, 4);
DumpGasStruct (DataPtr, 4, GAS_LENGTH);
PrintFieldName (4, L"Address Size");
Print (L"0x%x\n", AddrSize[Index]);
DataPtr += GAS_LENGTH;