]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.c
refine the code and add more security check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiCHAP.c
index dc6567498fb87fc12b84059e69337397652c553b..5b94266e1f09abb517576efb88a3d53d9d685d71 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This file is for Challenge-Handshake Authentication Protocol (CHAP) Configuration.\r
\r
-Copyright (c) 2004 - 2009, Intel Corporation.<BR>\r
+\r
+Copyright (c) 2004 - 2010, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -18,19 +18,19 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 EFI_GUID  mIScsiCHAPAuthInfoGuid = ISCSI_CHAP_AUTH_INFO_GUID;\r
 \r
 /**\r
-  Initator caculates its own expected hash value. \r
-  \r
-  @param[in]   ChapIdentifier     iSCSI CHAP identifier sent by authenticator.  \r
-  @param[in]   ChapSecret         iSCSI CHAP secret of the authenticator.   \r
+  Initator caculates its own expected hash value.\r
+\r
+  @param[in]   ChapIdentifier     iSCSI CHAP identifier sent by authenticator.\r
+  @param[in]   ChapSecret         iSCSI CHAP secret of the authenticator.\r
   @param[in]   SecretLength       The length of iSCSI CHAP secret.\r
-  @param[in]   ChapChallenge      The challenge message sent by authenticator.  \r
+  @param[in]   ChapChallenge      The challenge message sent by authenticator.\r
   @param[in]   ChallengeLength    The length of iSCSI CHAP challenge message.\r
   @param[out]  ChapResponse       The calculation of the expected hash value.\r
-  \r
+\r
   @retval EFI_SUCCESS             The expected hash value was caculatedly successfully.\r
-  @retval EFI_PROTOCOL_ERROR      The length of the secret should be at least the \r
+  @retval EFI_PROTOCOL_ERROR      The length of the secret should be at least the\r
                                   length of the hash value for the hashing algorithm chosen.\r
-  @retval Others                  Other errors as indicated.                                \r
+  @retval Others                  Other errors as indicated.\r
 **/\r
 EFI_STATUS\r
 IScsiCHAPCalculateResponse (\r
@@ -75,10 +75,10 @@ IScsiCHAPCalculateResponse (
 \r
 /**\r
   The initator checks the CHAP response replied by target against its own\r
-  calculation of the expected hash value. \r
-  \r
-  @param[in]   AuthData             iSCSI CHAP authentication data. \r
-  @param[in]   TargetResponse       The response from target.    \r
+  calculation of the expected hash value.\r
+\r
+  @param[in]   AuthData             iSCSI CHAP authentication data.\r
+  @param[in]   TargetResponse       The response from target.\r
 \r
   @retval EFI_SUCCESS               The response from target passed authentication.\r
   @retval EFI_SECURITY_VIOLATION    The response from target was not expected value.\r
@@ -106,7 +106,7 @@ IScsiCHAPAuthTarget (
             VerifyRsp\r
             );\r
 \r
-  if (CompareMem (VerifyRsp, TargetResponse, ISCSI_CHAP_RSP_LEN)) {\r
+  if (CompareMem (VerifyRsp, TargetResponse, ISCSI_CHAP_RSP_LEN) != 0) {\r
     Status = EFI_SECURITY_VIOLATION;\r
   }\r
 \r
@@ -116,7 +116,7 @@ IScsiCHAPAuthTarget (
 /**\r
   This function checks the received iSCSI Login Response during the security\r
   negotiation stage.\r
-  \r
+\r
   @param[in] Conn             The iSCSI connection.\r
 \r
   @retval EFI_SUCCESS          The Login Response passed the CHAP validation.\r
@@ -165,6 +165,7 @@ IScsiCHAPOnRspReceived (
   //\r
   KeyValueList = IScsiBuildKeyValueList ((CHAR8 *) Data, Len);\r
   if (KeyValueList == NULL) {\r
+    FreePool (Data);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -294,7 +295,7 @@ ON_EXIT:
 \r
   IScsiFreeKeyValueList (KeyValueList);\r
 \r
-  gBS->FreePool (Data);\r
+  FreePool (Data);\r
 \r
   return Status;\r
 }\r
@@ -421,8 +422,8 @@ IScsiCHAPToSendReq (
     break;\r
   }\r
 \r
-  gBS->FreePool (Response);\r
-  gBS->FreePool (Challenge);\r
+  FreePool (Response);\r
+  FreePool (Challenge);\r
 \r
   return Status;\r
 }\r