]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
MdeModulePkg:Modify the incorrect DestStr length in safe string functions
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Database.c
index c80f1db055b856d16acc00afece35a07ea742cf4..ec56795ebb1924942403472a062cc3129aecbc8c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation for EFI_HII_DATABASE_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2015, 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
@@ -15,12 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "HiiDatabase.h"\r
 \r
-//\r
-// Global variables\r
-//\r
-EFI_GUID mHiiDatabaseNotifyGuid = HII_DATABASE_NOTIFY_GUID;\r
-\r
-\r
 /**\r
   This function generates a HII_DATABASE_RECORD node and adds into hii database.\r
   This is a internal function.\r
@@ -86,7 +80,7 @@ GenerateHiiDatabaseRecord (
   // Backup the number of Hii handles\r
   //\r
   Private->HiiHandleCount++;\r
-  HiiHandle->Key = Private->HiiHandleCount;\r
+  HiiHandle->Key = (UINTN) Private->HiiHandleCount;\r
   //\r
   // Insert the handle to hii handle list of the whole database.\r
   //\r
@@ -804,7 +798,7 @@ InsertStringPackage (
   if (Language == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  AsciiStrCpy (Language, (CHAR8 *) PackageHdr + HeaderSize - LanguageSize);\r
+  AsciiStrCpyS (Language, LanguageSize / sizeof (CHAR8), (CHAR8 *) PackageHdr + HeaderSize - LanguageSize);\r
   for (Link = PackageList->StringPkgHdr.ForwardLink; Link != &PackageList->StringPkgHdr; Link = Link->ForwardLink) {\r
     StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
     if (HiiCompareLanguage (Language, StringPackage->StringPkgHdr->Language)) {\r
@@ -856,7 +850,7 @@ InsertStringPackage (
   //\r
   // Collect all font block info\r
   //\r
-  Status = FindStringBlock (Private, StringPackage, (EFI_STRING_ID) (-1), NULL, NULL, NULL, &StringPackage->MaxStringId);\r
+  Status = FindStringBlock (Private, StringPackage, (EFI_STRING_ID) (-1), NULL, NULL, NULL, &StringPackage->MaxStringId, NULL);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -1188,7 +1182,7 @@ InsertFontPackage (
   }\r
   FontInfo->FontStyle = FontPkgHdr->FontStyle;\r
   FontInfo->FontSize  = FontPkgHdr->Cell.Height;\r
-  StrCpy (FontInfo->FontName, FontPkgHdr->FontFamily);\r
+  StrCpyS (FontInfo->FontName, (FontInfoSize - OFFSET_OF(EFI_FONT_INFO,FontName)) / sizeof (CHAR16), FontPkgHdr->FontFamily);\r
 \r
   if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, NULL)) {\r
     Status = EFI_UNSUPPORTED;\r
@@ -2423,8 +2417,14 @@ AddPackages (
   //\r
   // Initialize Variables\r
   //\r
-  StringPkgIsAdd = FALSE;\r
-  FontPackage = NULL;\r
+  StringPkgIsAdd        = FALSE;\r
+  FontPackage           = NULL;\r
+  StringPackage         = NULL;\r
+  GuidPackage           = NULL;\r
+  FormPackage           = NULL;\r
+  ImagePackage          = NULL;\r
+  SimpleFontPackage     = NULL;\r
+  KeyboardLayoutPackage = NULL;\r
 \r
   //\r
   // Process the package list header\r
@@ -2511,6 +2511,7 @@ AddPackages (
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
+      ASSERT (StringPackage != NULL);\r
       Status = InvokeRegisteredFunction (\r
                  Private,\r
                  NotifyType,\r
@@ -3106,17 +3107,18 @@ HiiUpdatePackageList (
   @param  Handle                 An array of EFI_HII_HANDLE instances returned.\r
 \r
   @retval EFI_SUCCESS            The matching handles are outputed successfully.\r
-                                               HandleBufferLength is updated with the actual length.\r
+                                 HandleBufferLength is updated with the actual length.\r
   @retval EFI_BUFFER_TO_SMALL    The HandleBufferLength parameter indicates that\r
                                  Handle is too small to support the number of\r
                                  handles. HandleBufferLength is updated with a\r
                                  value that will  enable the data to fit.\r
   @retval EFI_NOT_FOUND          No matching handle could not be found in database.\r
-  @retval EFI_INVALID_PARAMETER  Handle or HandleBufferLength was NULL.\r
-  \r
+  @retval EFI_INVALID_PARAMETER  HandleBufferLength was NULL.\r
+  @retval EFI_INVALID_PARAMETER  The value referenced by HandleBufferLength was not\r
+                                 zero and Handle was NULL.\r
   @retval EFI_INVALID_PARAMETER  PackageType is not a EFI_HII_PACKAGE_TYPE_GUID but\r
-                                                     PackageGuid is not NULL, PackageType is a EFI_HII_\r
-                                                     PACKAGE_TYPE_GUID but PackageGuid is NULL.\r
+                                 PackageGuid is not NULL, PackageType is a EFI_HII_\r
+                                 PACKAGE_TYPE_GUID but PackageGuid is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3269,7 +3271,9 @@ HiiListPackageLists (
                                  value that will enable the data to fit.\r
   @retval EFI_NOT_FOUND          The specifiecd Handle could not be found in the\r
                                  current database.\r
-  @retval EFI_INVALID_PARAMETER  Handle or Buffer or BufferSize was NULL.\r
+  @retval EFI_INVALID_PARAMETER  BufferSize was NULL.\r
+  @retval EFI_INVALID_PARAMETER  The value referenced by BufferSize was not zero \r
+                                 and Buffer was NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3287,13 +3291,13 @@ HiiExportPackageLists (
   HII_DATABASE_RECORD                 *Node;\r
   UINTN                               UsedSize;\r
 \r
-  if (This == NULL || BufferSize == NULL || Handle == NULL) {\r
+  if (This == NULL || BufferSize == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (*BufferSize > 0 && Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  if (!IsHiiHandleValid (Handle)) {\r
+  if ((Handle != NULL) && (!IsHiiHandleValid (Handle))) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -3419,7 +3423,7 @@ HiiRegisterPackageNotify (
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &Notify->NotifyHandle,\r
-                  &mHiiDatabaseNotifyGuid,\r
+                  &gEfiCallerIdGuid,\r
                   NULL,\r
                   NULL\r
                   );\r
@@ -3477,7 +3481,7 @@ HiiUnregisterPackageNotify (
 \r
   Status = gBS->OpenProtocol (\r
                   NotificationHandle,\r
-                  &mHiiDatabaseNotifyGuid,\r
+                  &gEfiCallerIdGuid,\r
                   NULL,\r
                   NULL,\r
                   NULL,\r
@@ -3498,7 +3502,7 @@ HiiUnregisterPackageNotify (
       RemoveEntryList (&Notify->DatabaseNotifyEntry);\r
       Status = gBS->UninstallMultipleProtocolInterfaces (\r
                       Notify->NotifyHandle,\r
-                      &mHiiDatabaseNotifyGuid,\r
+                      &gEfiCallerIdGuid,\r
                       NULL,\r
                       NULL\r
                       );\r
@@ -3531,7 +3535,9 @@ HiiUnregisterPackageNotify (
                                  number of GUIDs. KeyGuidBufferLength is\r
                                  updated with a value that will enable the data to\r
                                  fit.\r
-  @retval EFI_INVALID_PARAMETER  The KeyGuidBuffer or KeyGuidBufferLength was NULL.\r
+  @retval EFI_INVALID_PARAMETER  The KeyGuidBufferLength is NULL.\r
+  @retval EFI_INVALID_PARAMETER  The value referenced by KeyGuidBufferLength is not\r
+                                 zero and KeyGuidBuffer is NULL.\r
   @retval EFI_NOT_FOUND          There was no keyboard layout.\r
 \r
 **/\r