]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeHstiLib/HstiDxe.c
MdePkg DxeHstiLib: Fix ErrorString pointer incorrectly calculated
[mirror_edk2.git] / MdePkg / Library / DxeHstiLib / HstiDxe.c
index c7a5769bf582196a4f05602defac402dd4ef69c9..d08d8def0cb5fdf3b91a84720cd189faf6fd556a 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2018, 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
@@ -200,18 +200,18 @@ InternalHstiIsValidTable (
   //\r
   // Check ImplementationID\r
   //\r
-  for (Index = 0; Index < sizeof(Hsti->ImplementationID); Index++) {\r
+  for (Index = 0; Index < sizeof(Hsti->ImplementationID)/sizeof(Hsti->ImplementationID[0]); Index++) {\r
     if (Hsti->ImplementationID[Index] == 0) {\r
       break;\r
     }\r
   }\r
-  if (Index == sizeof(Hsti->ImplementationID)) {\r
-    DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n"));\r
+  if (Index == sizeof(Hsti->ImplementationID)/sizeof(Hsti->ImplementationID[0])) {\r
+    DEBUG ((EFI_D_ERROR, "ImplementationID has no NUL CHAR\n"));\r
     return FALSE;\r
   }\r
 \r
   ErrorStringSize = HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY) - Hsti->SecurityFeaturesSize * 3;\r
-  ErrorString = (CHAR16 *)((UINTN)Hsti + sizeof(ADAPTER_INFO_PLATFORM_SECURITY) - Hsti->SecurityFeaturesSize * 3);\r
+  ErrorString = (CHAR16 *)((UINTN)Hsti + sizeof(ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 3);\r
 \r
   //\r
   // basic check for ErrorString\r
@@ -297,7 +297,7 @@ HstiLibSetTable (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   HstiAip->Hsti = AllocateCopyPool (HstiSize, Hsti);\r
-  if (HstiAip == NULL) {\r
+  if (HstiAip->Hsti == NULL) {\r
     FreePool (HstiAip);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -393,7 +393,7 @@ InternalHstiRecordFeaturesVerified (
   UINT8                            *SecurityFeaturesVerified;\r
   EFI_STATUS                       Status;\r
 \r
-  Aip = InternalHstiFindAip (Role, ImplementationID, &Hsti, &HstiSize);\r
+  Aip = InternalHstiFindAip (Role, ImplementationID, (VOID **)&Hsti, &HstiSize);\r
   if (Aip == NULL) {\r
     return EFI_NOT_STARTED;\r
   }\r
@@ -416,6 +416,7 @@ InternalHstiRecordFeaturesVerified (
                   Hsti,\r
                   HstiSize\r
                   );\r
+  FreePool (Hsti);\r
   return Status;\r
 }\r
 \r
@@ -518,7 +519,7 @@ InternalHstiRecordErrorString (
   UINTN                            Offset;\r
   EFI_STATUS                       Status;\r
 \r
-  Aip = InternalHstiFindAip (Role, ImplementationID, &Hsti, &HstiSize);\r
+  Aip = InternalHstiFindAip (Role, ImplementationID, (VOID **)&Hsti, &HstiSize);\r
   if (Aip == NULL) {\r
     return EFI_NOT_STARTED;\r
   }\r
@@ -545,6 +546,8 @@ InternalHstiRecordErrorString (
                   NewHsti,\r
                   NewHstiSize\r
                   );\r
+  FreePool (Hsti);\r
+  FreePool (NewHsti);\r
   return Status;\r
 }\r
 \r