From nobody Sat Nov 2 14:39:54 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487917623441396.193663936715; Thu, 23 Feb 2017 22:27:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0156982166; Thu, 23 Feb 2017 22:27:02 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 82FA482164 for ; Thu, 23 Feb 2017 22:27:00 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2017 22:27:00 -0800 Received: from shwdeopenpsi116.ccr.corp.intel.com ([10.239.9.7]) by fmsmga002.fm.intel.com with ESMTP; 23 Feb 2017 22:26:58 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,200,1484035200"; d="scan'208";a="1134269823" From: Zhang Lubo To: edk2-devel@lists.01.org Date: Fri, 24 Feb 2017 14:26:57 +0800 Message-Id: <1487917617-10748-1-git-send-email-lubo.zhang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [patch] NetworkPkg: Add check logic for some variable in iSCSI driver. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add check logic for some attempt variable to enhance code in iSCSI. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo Cc: Ye Ting Cc: Fu Siyuan Cc: Wu Jiaxin --- NetworkPkg/IScsiDxe/IScsiConfig.c | 75 +++++++++++++++++++++--------------= ---- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiC= onfig.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; =20 ZeroMem (AttemptNameList, sizeof (AttemptNameList)); =20 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) { Attempt =3D NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, = Link); // // Normal session configuration parameters. // SessionConfigData =3D &Attempt->SessionConfigData; =20 + ASSERT ((Attempt->AttemptConfigIndex > 0) && (Attempt->AttemptConfigIn= dex <=3D FixedPcdGet8 (PcdMaxIScsiAttemptNumber))); Index =3D Attempt->AttemptConfigIndex - 1; =20 // // 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) =3D L':'; - *(AttemptNameList + StrLen (AttemptNameList)) =3D L' '; + + StringLen =3D StrLen (AttemptNameList); + ASSERT (StringLen > 2); + *(AttemptNameList + StringLen - 2) =3D L':'; + *(AttemptNameList + StringLen) =3D L' '; =20 AsciiStrToUnicodeStrS ( Attempt->AttemptName, IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index, - ATTEMPT_NAME_SIZE + ATTEMPT_NAME_LIST_SIZE - ATTEMPT_NAME_SIZE * Index ); =20 IfrNvData->ISCSIBootEnableList[Index] =3D SessionConfigData->= Enabled; IfrNvData->ISCSIIpAddressTypeList[Index] =3D SessionConfigData->= IpMode; =20 @@ -1199,10 +1204,11 @@ IScsiConvertlfrNvDataToAttemptConfigDataByKeyword ( EFI_IP_ADDRESS Gateway; EFI_INPUT_KEY Key; UINT64 Lun; EFI_STATUS Status; =20 + Attempt =3D NULL; ZeroMem (IScsiName, sizeof (IScsiName)); =20 if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) { return EFI_SUCCESS; =20 @@ -1726,11 +1732,11 @@ IScsiConvertlfrNvDataToAttemptConfigDataByKeyword ( =20 =20 // // Record the user configuration information in NVR. // - + ASSERT (Attempt !=3D 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; =20 + AttemptConfigData =3D NULL; // // Is User creating a new attempt? // NewAttempt =3D FALSE; =20 @@ -2749,41 +2756,40 @@ IScsiConfigProcessDefault ( L"InitialAttemptOrder", &gIScsiConfigGuid, &AttemptConfigOrderSize ); =20 - if (AttemptConfigOrder !=3D NULL) { - - for (Index =3D 0; Index < AttemptConfigOrderSize / sizeof (UINT8); I= ndex++) { - UnicodeSPrint ( - mPrivate->PortString, - (UINTN) ISCSI_NAME_IFR_MAX_SIZE, - L"Attempt %d", - (UINTN) AttemptConfigOrder[Index] - ); - GetVariable2 ( - mPrivate->PortString, - &gEfiIScsiInitiatorNameProtocolGuid, - (VOID**)&AttemptConfigData, - NULL - ); - if (AttemptConfigData =3D=3D NULL || AttemptConfigData->Actived = =3D=3D ISCSI_ACTIVE_ENABLED) { - continue; - } - - break; - } + ASSERT (AttemptConfigOrder !=3D NULL); =20 - if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) { - CreatePopUp ( - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, - &Key, - L"Can not create more attempts, Please configure the PcdMaxIScsi= AttemptNumber if needed!", - NULL - ); - return EFI_UNSUPPORTED; + for (Index =3D 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Ind= ex++) { + UnicodeSPrint ( + mPrivate->PortString, + (UINTN) ISCSI_NAME_IFR_MAX_SIZE, + L"Attempt %d", + (UINTN) AttemptConfigOrder[Index] + ); + GetVariable2 ( + mPrivate->PortString, + &gEfiIScsiInitiatorNameProtocolGuid, + (VOID**)&AttemptConfigData, + NULL + ); + if (AttemptConfigData =3D=3D NULL || AttemptConfigData->Actived =3D= =3D ISCSI_ACTIVE_ENABLED) { + continue; } + =20 + break; + } + =20 + if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"Can not create more attempts, Please configure the PcdMaxIScsiAt= temptNumber if needed!", + NULL + ); + return EFI_UNSUPPORTED; } =20 if (AttemptConfigOrder !=3D NULL) { FreePool (AttemptConfigOrder); } @@ -2796,10 +2802,11 @@ IScsiConfigProcessDefault ( NicInfo->HwAddressSize, NicInfo->VlanId, MacString ); =20 + ASSERT (AttemptConfigData !=3D NULL); UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof= (AttemptConfigData->MacString)); AttemptConfigData->NicIndex =3D NicIndex; AttemptConfigData->Actived =3D ISCSI_ACTIVE_ENABLED; =20 // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel