Follow UEFI specification to add context check and init in BaseCrypto2Hash(), 
so that other function can get proper status on hash operation.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <jiewen....@intel.com>
Cc: "Zhang, Chao B" <chao.b.zh...@intel.com>
---
 SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c 
b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c
index dab0299..94057ab 100644
--- a/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c
+++ b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c
@@ -358,6 +358,7 @@ BaseCrypto2Hash (
   UINTN                    CtxSize;
   BOOLEAN                  Ret;
   EFI_STATUS               Status;
+  HASH2_INSTANCE_DATA      *Instance;
 
   Status = EFI_SUCCESS;
 
@@ -373,6 +374,13 @@ BaseCrypto2Hash (
   if (HashInfo == NULL) {
     return EFI_UNSUPPORTED;
   }
+  
+  Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);
+  if (Instance->HashContext != NULL) {
+    FreePool (Instance->HashContext);
+  }
+  Instance->HashInfoContext = NULL;
+  Instance->HashContext = NULL;
 
   //
   // Start hash sequence
@@ -392,6 +400,12 @@ BaseCrypto2Hash (
     goto Done;
   }
 
+  //
+  // Setup the context
+  //
+  Instance->HashContext = HashCtx;
+  Instance->HashInfoContext = HashInfo;
+
   Ret = HashInfo->Update (HashCtx, Message, MessageSize);
   if (!Ret) {
     Status = EFI_OUT_OF_RESOURCES;
@@ -404,7 +418,12 @@ BaseCrypto2Hash (
     goto Done;
   }
 Done:
+  //
+  // Cleanup the context
+  //
   FreePool (HashCtx);
+  Instance->HashInfoContext = NULL;
+  Instance->HashContext = NULL;
   return Status;
 }
 
-- 
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to