public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [patch] NetworkPkg: Add check logic for some variable in iSCSI driver.
@ 2017-02-24  6:26 Zhang Lubo
  0 siblings, 0 replies; only message in thread
From: Zhang Lubo @ 2017-02-24  6:26 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ye Ting, Fu Siyuan, Wu Jiaxin

Add check logic for some attempt variable to enhance code in iSCSI.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/IScsiDxe/IScsiConfig.c | 75 +++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 34 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c
index b169620..f8c0a61 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -628,37 +628,42 @@ IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (
   ISCSI_SESSION_CONFIG_NVDATA   *SessionConfigData;
   ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;
   CHAR16                        AttemptNameList[ATTEMPT_NAME_LIST_SIZE];
   EFI_IP_ADDRESS                Ip;
   UINTN                         Index;
+  UINTN                         StringLen;
 
   ZeroMem (AttemptNameList, sizeof (AttemptNameList));
 
   NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
     Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
     //
     // Normal session configuration parameters.
     //
     SessionConfigData                 = &Attempt->SessionConfigData;
 
+    ASSERT ((Attempt->AttemptConfigIndex > 0) && (Attempt->AttemptConfigIndex <= FixedPcdGet8 (PcdMaxIScsiAttemptNumber)));
     Index   = Attempt->AttemptConfigIndex - 1;
 
     //
     // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
     //
     AsciiStrToUnicodeStrS (
       Attempt->AttemptName,
       AttemptNameList + StrLen (AttemptNameList),
-      ATTEMPT_NAME_LIST_SIZE
+      ATTEMPT_NAME_LIST_SIZE - StrLen (AttemptNameList)
     );
-    *(AttemptNameList + StrLen (AttemptNameList) - 2) = L':';
-    *(AttemptNameList + StrLen (AttemptNameList))     = L' ';
+
+    StringLen = StrLen (AttemptNameList);
+    ASSERT (StringLen > 2);
+    *(AttemptNameList + StringLen - 2) = L':';
+    *(AttemptNameList + StringLen)     = L' ';
 
     AsciiStrToUnicodeStrS (
       Attempt->AttemptName,
       IfrNvData->ISCSIAttemptName  + ATTEMPT_NAME_SIZE * Index,
-      ATTEMPT_NAME_SIZE
+      ATTEMPT_NAME_LIST_SIZE - ATTEMPT_NAME_SIZE * Index
     );
 
     IfrNvData->ISCSIBootEnableList[Index]          = SessionConfigData->Enabled;
     IfrNvData->ISCSIIpAddressTypeList[Index]       = SessionConfigData->IpMode;
 
@@ -1199,10 +1204,11 @@ IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
   EFI_IP_ADDRESS                   Gateway;
   EFI_INPUT_KEY                    Key;
   UINT64                           Lun;
   EFI_STATUS                       Status;
 
+  Attempt = NULL;
   ZeroMem (IScsiName, sizeof (IScsiName));
 
   if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) {
     return EFI_SUCCESS;
 
@@ -1726,11 +1732,11 @@ IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
 
 
   //
   // Record the user configuration information in NVR.
   //
-
+  ASSERT (Attempt != NULL);
   UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", Attempt->AttemptConfigIndex);
   return gRT->SetVariable (
                 mPrivate->PortString,
                 &gEfiIScsiInitiatorNameProtocolGuid,
                 ISCSI_CONFIG_VAR_ATTR,
@@ -2705,10 +2711,11 @@ IScsiConfigProcessDefault (
   UINT8                       *AttemptConfigOrder;
   UINTN                       AttemptConfigOrderSize;
   UINTN                       Index;
   EFI_INPUT_KEY               Key;
 
+  AttemptConfigData = NULL;
   //
   // Is User creating a new attempt?
   //
   NewAttempt = FALSE;
 
@@ -2749,41 +2756,40 @@ IScsiConfigProcessDefault (
                            L"InitialAttemptOrder",
                            &gIScsiConfigGuid,
                            &AttemptConfigOrderSize
                            );
 
-    if (AttemptConfigOrder != NULL) {
-
-      for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
-        UnicodeSPrint (
-          mPrivate->PortString,
-          (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
-          L"Attempt %d",
-          (UINTN) AttemptConfigOrder[Index]
-          );
-        GetVariable2 (
-                     mPrivate->PortString,
-                     &gEfiIScsiInitiatorNameProtocolGuid,
-                     (VOID**)&AttemptConfigData,
-                     NULL
-                     );
-        if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
-          continue;
-        }
-
-        break;
-      }
+    ASSERT (AttemptConfigOrder != NULL);
 
-      if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
-        CreatePopUp (
-          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
-          &Key,
-          L"Can not create more attempts, Please configure the PcdMaxIScsiAttemptNumber if needed!",
-          NULL
-          );
-        return EFI_UNSUPPORTED;
+    for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
+      UnicodeSPrint (
+        mPrivate->PortString,
+        (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
+        L"Attempt %d",
+        (UINTN) AttemptConfigOrder[Index]
+        );
+      GetVariable2 (
+                   mPrivate->PortString,
+                   &gEfiIScsiInitiatorNameProtocolGuid,
+                   (VOID**)&AttemptConfigData,
+                   NULL
+                   );
+      if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
+        continue;
       }
+    
+      break;
+    }
+    
+    if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
+      CreatePopUp (
+        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+        &Key,
+        L"Can not create more attempts, Please configure the PcdMaxIScsiAttemptNumber if needed!",
+        NULL
+        );
+      return EFI_UNSUPPORTED;
     }
 
     if (AttemptConfigOrder != NULL) {
       FreePool (AttemptConfigOrder);
     }
@@ -2796,10 +2802,11 @@ IScsiConfigProcessDefault (
       NicInfo->HwAddressSize,
       NicInfo->VlanId,
       MacString
       );
 
+    ASSERT (AttemptConfigData != NULL);
     UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof (AttemptConfigData->MacString));
     AttemptConfigData->NicIndex = NicIndex;
     AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
 
     //
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-02-24  6:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-24  6:26 [patch] NetworkPkg: Add check logic for some variable in iSCSI driver Zhang Lubo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox