]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: acpiview: PPTT: Validate global pointers before use
authorKrzysztof Koch <krzysztof.koch@arm.com>
Mon, 20 Jan 2020 11:13:48 +0000 (19:13 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 11 Feb 2020 02:12:45 +0000 (02:12 +0000)
Check if the NumberOfPrivateResources, ProcessorTopologyStructureType
and ProcessorTopologyStructureLength pointers have been successfully
updated before they are used for further table parsing.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c

index 6254b9913fffb429fc54bb1301bf3e4b2e5bf161..675ba75f02b367cd5ad9f2ac23c30ed0ab58f286 100644 (file)
@@ -264,6 +264,17 @@ DumpProcessorHierarchyNodeStructure (
              PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)\r
              );\r
 \r
+  // Check if the values used to control the parsing logic have been\r
+  // successfully read.\r
+  if (NumberOfPrivateResources == NULL) {\r
+    IncrementErrorCount ();\r
+    Print (\r
+      L"ERROR: Insufficient Processor Hierarchy Node length. Length = %d.\n",\r
+      Length\r
+      );\r
+    return;\r
+  }\r
+\r
   // Make sure the Private Resource array lies inside this structure\r
   if (Offset + (*NumberOfPrivateResources * sizeof (UINT32)) > Length) {\r
     IncrementErrorCount ();\r
@@ -387,6 +398,7 @@ ParseAcpiPptt (
              AcpiTableLength,\r
              PARSER_PARAMS (PpttParser)\r
              );\r
+\r
   ProcessorTopologyStructurePtr = Ptr + Offset;\r
 \r
   while (Offset < AcpiTableLength) {\r
@@ -400,6 +412,19 @@ ParseAcpiPptt (
       PARSER_PARAMS (ProcessorTopologyStructureHeaderParser)\r
       );\r
 \r
+    // Check if the values used to control the parsing logic have been\r
+    // successfully read.\r
+    if ((ProcessorTopologyStructureType == NULL) ||\r
+        (ProcessorTopologyStructureLength == NULL)) {\r
+      IncrementErrorCount ();\r
+      Print (\r
+        L"ERROR: Insufficient remaining table buffer length to read the " \\r
+          L"processor topology structure header. Length = %d.\n",\r
+        AcpiTableLength - Offset\r
+        );\r
+      return;\r
+    }\r
+\r
     // Make sure the PPTT structure lies inside the table\r
     if ((Offset + *ProcessorTopologyStructureLength) > AcpiTableLength) {\r
       IncrementErrorCount ();\r