]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
ShellPkg: acpiview: Prevent infinite loop if structure length is 0
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Srat / SratParser.c
index 3613900ae322483fdd3d3383de4e22ba75b2128b..6f66be68cc0bed14811a0432c61a79fd47c54890 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SRAT table parser\r
 \r
-  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.\r
+  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
   @par Reference(s):\r
@@ -412,14 +412,16 @@ ParseAcpiSrat (
       return;\r
     }\r
 \r
-    // Make sure the SRAT structure lies inside the table\r
-    if ((Offset + *SratRALength) > AcpiTableLength) {\r
+    // Validate Static Resource Allocation Structure length\r
+    if ((*SratRALength == 0) ||\r
+        ((Offset + (*SratRALength)) > AcpiTableLength)) {\r
       IncrementErrorCount ();\r
       Print (\r
-        L"ERROR: Invalid SRAT structure length. SratRALength = %d. " \\r
-          L"RemainingTableBufferLength = %d. SRAT parsing aborted.\n",\r
+        L"ERROR: Invalid Static Resource Allocation Structure length. " \\r
+          L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",\r
         *SratRALength,\r
-        AcpiTableLength - Offset\r
+        Offset,\r
+        AcpiTableLength\r
         );\r
       return;\r
     }\r