]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
pointer verification (not NULL) and buffer overrun fixes.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / QueryTable.c
index c04dba5b7652534cc6ff59a12a98f370cf9e287c..7b7e5928bd204923a96cbf3740e773bcffcc67a7 100644 (file)
@@ -2,7 +2,7 @@
   Build a table, each item is (Key, Info) pair.\r
   And give a interface of query a string out of a table.\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
@@ -2921,27 +2921,8 @@ TABLE_ITEM  StructureTypeInfoTable[] = {
 };\r
 \r
 \r
-UINT8\r
-QueryTable (\r
-  IN  TABLE_ITEM    *Table,\r
-  IN  UINTN         Number,\r
-  IN  UINT8         Key,\r
-  IN  OUT CHAR16    *Info\r
-  )\r
-/*++\r
-Routine Description:\r
-  Function Description\r
-    Given a table and a Key, return the responding info.\r
-\r
-  Arguments:\r
-    Table   -  The begin address of table\r
-    Number  -  The number of table items\r
-    Key     -  The query Key\r
-    Info    -  Input as empty buffer; output as data buffer.\r
-\r
-  Returns:\r
-    if Key found   - return found Key and Info\r
-    if Key unfound - return QUERY_TABLE_UNFOUND, Info=NULL\r
+/**\r
+  Given a table and a Key, return the responding info.\r
 \r
   Notes:\r
     Table[Index].Key is change from UINT8 to UINT16,\r
@@ -2955,7 +2936,23 @@ Routine Description:
     Then all the Key Value between Low and High gets the same string\r
     L"Unused".\r
 \r
+  @param[in] Table    The begin address of table.\r
+  @param[in] Number   The number of table items.\r
+  @param[in] Key      The query Key.\r
+  @param[in,out] Info Input as empty buffer; output as data buffer.\r
+  @param[in] InfoLen  The max number of characters for Info.\r
+\r
+  @return the found Key and Info is valid.\r
+  @retval QUERY_TABLE_UNFOUND and Info should be NULL.\r
 **/\r
+UINT8\r
+QueryTable (\r
+  IN  TABLE_ITEM    *Table,\r
+  IN  UINTN         Number,\r
+  IN  UINT8         Key,\r
+  IN  OUT CHAR16    *Info,\r
+  IN  UINTN         InfoLen\r
+  )\r
 {\r
   UINTN Index;\r
   //\r
@@ -2971,7 +2968,7 @@ Routine Description:
     // Check if Key is in the range\r
     //\r
     if (High > Low && Key >= Low && Key <= High) {\r
-      StrCpy (Info, Table[Index].Info);\r
+      StrnCpy (Info, Table[Index].Info, InfoLen-1);\r
       StrCat (Info, L"\n");\r
       return Key;\r
     }\r
@@ -2979,13 +2976,13 @@ Routine Description:
     // Check if Key == Value in the table\r
     //\r
     if (Table[Index].Key == Key) {\r
-      StrCpy (Info, Table[Index].Info);\r
+      StrnCpy (Info, Table[Index].Info, InfoLen-1);\r
       StrCat (Info, L"\n");\r
       return Key;\r
     }\r
   }\r
 \r
-  StrCpy (Info, L"Undefined Value\n");\r
+  StrnCpy (Info, L"Undefined Value\n", InfoLen);\r
   return QUERY_TABLE_UNFOUND;\r
 }\r
 \r
@@ -3069,7 +3066,7 @@ PrintBitsInfo (
     CHAR16  Info[66]; \\r
     Num = sizeof (Table) / sizeof (TABLE_ITEM); \\r
     ZeroMem (Info, sizeof (Info)); \\r
-    QueryTable (Table, Num, Key, Info); \\r
+    QueryTable (Table, Num, Key, Info, sizeof(Info)/sizeof(Info[0])); \\r
     Print (Info); \\r
   } while (0);\r
 \r