]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
pointer verification (not NULL) and buffer overrun fixes.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Pci.c
index 56d5f7fd6f9fa8dbd9f55d8974df8a57b7b2fdc1..d3a33e207ccdec16c3b0dd7c37cfadf84ab8e2da 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for Pci shell Debug1 function.\r
 \r
-  Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -1938,14 +1938,29 @@ ShellCommandRunPci (
     }\r
   } else {\r
 \r
+    if (ShellCommandLineGetCount(Package) == 2) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
 \r
+    if (ShellCommandLineGetCount(Package) > 4) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
+    if (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetValue(Package, L"-s") == NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-s");\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
     //\r
     // Get all instances of PciRootBridgeIo. Allocate space for 1 EFI_HANDLE and\r
     // call LibLocateHandle(), if EFI_BUFFER_TOO_SMALL is returned, allocate enough\r
     // space for handles and call it again.\r
     //\r
     HandleBufSize = sizeof (EFI_HANDLE);\r
-    HandleBuf     = (EFI_HANDLE *) AllocatePool (HandleBufSize);\r
+    HandleBuf     = (EFI_HANDLE *) AllocateZeroPool (HandleBufSize);\r
     if (HandleBuf == NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);\r
       ShellStatus = SHELL_OUT_OF_RESOURCES;\r
@@ -1987,7 +2002,7 @@ ShellCommandRunPci (
     //\r
     // Argument Count == 1(no other argument): enumerate all pci functions\r
     //\r
-    if (ShellCommandLineGetCount(Package) == 0) {\r
+    if (ShellCommandLineGetCount(Package) == 1) {\r
       gST->ConOut->QueryMode (\r
                     gST->ConOut,\r
                     gST->ConOut->Mode->Mode,\r
@@ -2134,20 +2149,6 @@ ShellCommandRunPci (
       goto Done;\r
     }\r
 \r
-    if (ShellCommandLineGetCount(Package) == 1) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-      goto Done;\r
-    }\r
-    //\r
-    // Arg count >= 3, dump binary of specified function, interpret if necessary\r
-    //\r
-    if (ShellCommandLineGetCount(Package) > 3) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-      goto Done;\r
-    }\r
-\r
     ExplainData                   = FALSE;\r
     Segment                       = 0;\r
     Bus                           = 0;\r
@@ -2159,7 +2160,7 @@ ShellCommandRunPci (
 \r
     Temp = ShellCommandLineGetValue(Package, L"-s");\r
     if (Temp != NULL) {\r
-      Segment = (UINT16) StrHexToUintn (Temp);\r
+      Segment = (UINT16) ShellStrToUintn (Temp);\r
     }\r
 \r
     //\r
@@ -2168,7 +2169,7 @@ ShellCommandRunPci (
     //\r
     Temp = ShellCommandLineGetRawValue(Package, 1);\r
     if (Temp != NULL) {\r
-      Bus = (UINT16)StrHexToUintn(Temp);\r
+      Bus = (UINT16)ShellStrToUintn(Temp);\r
       if (Bus > MAX_BUS_NUMBER) {\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
@@ -2177,7 +2178,7 @@ ShellCommandRunPci (
     }\r
     Temp = ShellCommandLineGetRawValue(Package, 2);\r
     if (Temp != NULL) {\r
-      Device = (UINT16) StrHexToUintn(Temp);\r
+      Device = (UINT16) ShellStrToUintn(Temp);\r
       if (Device > MAX_DEVICE_NUMBER){\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
@@ -2187,7 +2188,7 @@ ShellCommandRunPci (
 \r
     Temp = ShellCommandLineGetRawValue(Package, 3);\r
     if (Temp != NULL) {\r
-      Func = (UINT16) StrHexToUintn(Temp);\r
+      Func = (UINT16) ShellStrToUintn(Temp);\r
       if (Func > MAX_FUNCTION_NUMBER){\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
@@ -2469,21 +2470,22 @@ Returns:
   // if a bus typed one is found and its bus range covers bus, this handle\r
   // is the handle we are looking for.\r
   //\r
-  if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) {\r
-    *IsEnd = TRUE;\r
-  }\r
 \r
   while ((*Descriptors)->Desc != ACPI_END_TAG_DESCRIPTOR) {\r
     if ((*Descriptors)->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) {\r
       *MinBus = (UINT16) (*Descriptors)->AddrRangeMin;\r
       *MaxBus = (UINT16) (*Descriptors)->AddrRangeMax;\r
       (*Descriptors)++;\r
-      break;\r
+      return (EFI_SUCCESS);\r
     }\r
 \r
     (*Descriptors)++;\r
   }\r
 \r
+  if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) {\r
+    *IsEnd = TRUE;\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -4496,7 +4498,7 @@ PciExplainPciExpress (
 \r
   ExtendRegSize = 0x1000 - 0x100;\r
 \r
-  ExRegBuffer   = (UINT8 *) AllocatePool (ExtendRegSize);\r
+  ExRegBuffer   = (UINT8 *) AllocateZeroPool (ExtendRegSize);\r
 \r
   //\r
   // PciRootBridgeIo protocol should support pci express extend space IO\r