]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
authorKrzysztof Koch <krzysztof.koch@arm.com>
Mon, 22 Jul 2019 22:50:21 +0000 (15:50 -0700)
committerJaben Carsey <jaben.carsey@intel.com>
Wed, 31 Jul 2019 16:52:43 +0000 (09:52 -0700)
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>
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c

index 8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e 100644 (file)
@@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
 \r
   @param [in] Ptr     Pointer to the start of the buffer.\r
   @param [in] Indent  Number of spaces to indent the output.\r
+  @param [in] Length  Length of the GAS structure buffer.\r
+\r
+  @retval Number of bytes parsed.\r
 **/\r
-VOID\r
+UINT32\r
 EFIAPI\r
 DumpGasStruct (\r
   IN UINT8*        Ptr,\r
-  IN UINT32        Indent\r
+  IN UINT32        Indent,\r
+  IN UINT32        Length\r
   )\r
 {\r
   Print (L"\n");\r
-  ParseAcpi (\r
-    TRUE,\r
-    Indent,\r
-    NULL,\r
-    Ptr,\r
-    GAS_LENGTH,\r
-    PARSER_PARAMS (GasParser)\r
-    );\r
+  return ParseAcpi (\r
+           TRUE,\r
+           Indent,\r
+           NULL,\r
+           Ptr,\r
+           Length,\r
+           PARSER_PARAMS (GasParser)\r
+           );\r
 }\r
 \r
 /**\r
@@ -621,7 +625,7 @@ DumpGas (
   IN UINT8*        Ptr\r
   )\r
 {\r
-  DumpGasStruct (Ptr, 2);\r
+  DumpGasStruct (Ptr, 2, GAS_LENGTH);\r
 }\r
 \r
 /**\r
index 7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01 100644 (file)
@@ -405,12 +405,16 @@ ParseAcpi (
 \r
   @param [in] Ptr     Pointer to the start of the buffer.\r
   @param [in] Indent  Number of spaces to indent the output.\r
+  @param [in] Length  Length of the GAS structure buffer.\r
+\r
+  @retval Number of bytes parsed.\r
 **/\r
-VOID\r
+UINT32\r
 EFIAPI\r
 DumpGasStruct (\r
   IN UINT8*        Ptr,\r
-  IN UINT32        Indent\r
+  IN UINT32        Indent,\r
+  IN UINT32        Length\r
   );\r
 \r
 /**\r
index 1efcbd40f86efdabed2152540a415db8a950fb71..c6929695a1032c57761ef85002d6c51b7800ce23 100644 (file)
@@ -134,7 +134,7 @@ DumpDbgDeviceInfo (
   AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));\r
   while (Index < (*GasCount)) {\r
     PrintFieldName (4, L"BaseAddressRegister");\r
-    DumpGasStruct (DataPtr, 4);\r
+    DumpGasStruct (DataPtr, 4, GAS_LENGTH);\r
     PrintFieldName (4, L"Address Size");\r
     Print (L"0x%x\n", AddrSize[Index]);\r
     DataPtr += GAS_LENGTH;\r