]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
ShellPkg: acpiview: PPTT: Validate global pointers before use
[mirror_edk2.git] / 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