]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: acpiview: GTDT: Validate global pointers before use
authorKrzysztof Koch <krzysztof.koch@arm.com>
Mon, 20 Jan 2020 11:13:50 +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 global (in the scope of the GTDT parser) 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/Gtdt/GtdtParser.c

index 57174e14c80072f12b90e1996ebe8f0002d0c404..699a55b549ec3fa61bbd156898821055dc019199 100644 (file)
@@ -189,6 +189,18 @@ DumpGTBlock (
     PARSER_PARAMS (GtBlockParser)\r
     );\r
 \r
+  // Check if the values used to control the parsing logic have been\r
+  // successfully read.\r
+  if ((GtBlockTimerCount == NULL) ||\r
+      (GtBlockTimerOffset == NULL)) {\r
+    IncrementErrorCount ();\r
+    Print (\r
+      L"ERROR: Insufficient GT Block Structure length. Length = %d.\n",\r
+      Length\r
+      );\r
+    return;\r
+  }\r
+\r
   Offset = *GtBlockTimerOffset;\r
   Index = 0;\r
 \r
@@ -272,6 +284,18 @@ ParseAcpiGtdt (
     PARSER_PARAMS (GtdtParser)\r
     );\r
 \r
+  // Check if the values used to control the parsing logic have been\r
+  // successfully read.\r
+  if ((GtdtPlatformTimerCount == NULL) ||\r
+      (GtdtPlatformTimerOffset == NULL)) {\r
+    IncrementErrorCount ();\r
+    Print (\r
+      L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",\r
+      AcpiTableLength\r
+      );\r
+    return;\r
+  }\r
+\r
   TimerPtr = Ptr + *GtdtPlatformTimerOffset;\r
   Offset = *GtdtPlatformTimerOffset;\r
   Index = 0;\r
@@ -290,6 +314,19 @@ ParseAcpiGtdt (
       PARSER_PARAMS (GtPlatformTimerHeaderParser)\r
       );\r
 \r
+    // Check if the values used to control the parsing logic have been\r
+    // successfully read.\r
+    if ((PlatformTimerType == NULL) ||\r
+        (PlatformTimerLength == NULL)) {\r
+      IncrementErrorCount ();\r
+      Print (\r
+        L"ERROR: Insufficient remaining table buffer length to read the " \\r
+          L"Platform Timer Structure header. Length = %d.\n",\r
+        AcpiTableLength - Offset\r
+        );\r
+      return;\r
+    }\r
+\r
     // Make sure the Platform Timer is inside the table.\r
     if ((Offset + *PlatformTimerLength) > AcpiTableLength) {\r
       IncrementErrorCount ();\r