]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
SecurityPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Help.c
index 9aa77af97af172d3e069a3cf2278d6fe2a62374b..36c240d1221c88319b29a34fba46c161d6371e39 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Implement TPM2 help.\r
 \r
-Copyright (c) 2013 - 2016, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -97,7 +91,7 @@ CopyAuthSessionCommand (
   UINT8  *Buffer;\r
 \r
   Buffer = (UINT8 *)AuthSessionOut;\r
-  \r
+\r
   //\r
   // Add in Auth session\r
   //\r
@@ -141,7 +135,7 @@ CopyAuthSessionCommand (
     Buffer += sizeof(UINT16);\r
   }\r
 \r
-  return (UINT32)(UINTN)(Buffer - (UINT8 *)AuthSessionOut);\r
+  return (UINT32)((UINTN)Buffer - (UINTN)AuthSessionOut);\r
 }\r
 \r
 /**\r
@@ -150,7 +144,8 @@ CopyAuthSessionCommand (
   @param [in]  AuthSessionIn   Input AuthSession data in TPM2 response buffer\r
   @param [out] AuthSessionOut  Output AuthSession data\r
 \r
-  @return AuthSession size\r
+  @return 0    copy failed\r
+          else AuthSession size\r
 **/\r
 UINT32\r
 EFIAPI\r
@@ -171,6 +166,10 @@ CopyAuthSessionResponse (
   // nonce\r
   AuthSessionOut->nonce.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
   Buffer += sizeof(UINT16);\r
+  if (AuthSessionOut->nonce.size > sizeof(TPMU_HA)) {\r
+    DEBUG ((DEBUG_ERROR, "CopyAuthSessionResponse - nonce.size error %x\n", AuthSessionOut->nonce.size));\r
+    return 0;\r
+  }\r
 \r
   CopyMem (AuthSessionOut->nonce.buffer, Buffer, AuthSessionOut->nonce.size);\r
   Buffer += AuthSessionOut->nonce.size;\r
@@ -182,11 +181,15 @@ CopyAuthSessionResponse (
   // hmac\r
   AuthSessionOut->hmac.size = SwapBytes16 (ReadUnaligned16 ((UINT16 *)Buffer));\r
   Buffer += sizeof(UINT16);\r
+  if (AuthSessionOut->hmac.size > sizeof(TPMU_HA)) {\r
+    DEBUG ((DEBUG_ERROR, "CopyAuthSessionResponse - hmac.size error %x\n", AuthSessionOut->hmac.size));\r
+    return 0;\r
+  }\r
 \r
   CopyMem (AuthSessionOut->hmac.buffer, Buffer, AuthSessionOut->hmac.size);\r
   Buffer += AuthSessionOut->hmac.size;\r
 \r
-  return (UINT32)(UINTN)(Buffer - (UINT8 *)AuthSessionIn);\r
+  return (UINT32)((UINTN)Buffer - (UINTN)AuthSessionIn);\r
 }\r
 \r
 /**\r
@@ -239,7 +242,7 @@ IsHashAlgSupportedInHashAlgorithmMask(
 /**\r
   Copy TPML_DIGEST_VALUES into a buffer\r
 \r
-  @param[in,out] Buffer             Buffer to hold TPML_DIGEST_VALUES.\r
+  @param[in,out] Buffer             Buffer to hold copied TPML_DIGEST_VALUES compact binary.\r
   @param[in]     DigestList         TPML_DIGEST_VALUES to be copied.\r
   @param[in]     HashAlgorithmMask  HASH bits corresponding to the desired digests to copy.\r
 \r