From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 E7AE621D0A243 for ; Sun, 13 Aug 2017 22:07:38 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Aug 2017 22:10:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,372,1498546800"; d="scan'208";a="139856358" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga006.fm.intel.com with ESMTP; 13 Aug 2017 22:10:01 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 13 Aug 2017 22:10:01 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 13 Aug 2017 22:10:00 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.236]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.128]) with mapi id 14.03.0319.002; Mon, 14 Aug 2017 13:09:59 +0800 From: "Wu, Jiaxin" To: "Ye, Ting" , "edk2-devel@lists.01.org" CC: "Fu, Siyuan" , "Gao, Liming" , "Ni, Ruiyu" , "Dong, Eric" Thread-Topic: [PATCH v3][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries Thread-Index: AQHTDFLZfeyK3guypka+kD1kBFTeiKKCu8IAgACdfOA= Date: Mon, 14 Aug 2017 05:09:59 +0000 Message-ID: <895558F6EA4E3B41AC93A00D163B72741630A154@SHSMSX103.ccr.corp.intel.com> References: <1501762799-19344-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjYzMmIxYmMtZWVhOS00M2M0LTlmYzQtNTFlYmZiYmU5NThhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IjQ1R2VNQnFNVE5QZGxCd1wvcmRiT0IrbE1ENzZuMUZwTlZtMzkwVWRrN3VzPSJ9 x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Aug 2017 05:07:39 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks the comments, I agree it's better to check the returned value of Cre= ateDeviceNode. For the Dns, I can refine the code before the commit. As for the others, we= 'd better leave it to the owner for the decision whether to fix it or not. Thanks, Jiaxin > -----Original Message----- > From: Ye, Ting > Sent: Monday, August 14, 2017 11:28 AM > To: Wu, Jiaxin ; edk2-devel@lists.01.org > Cc: Fu, Siyuan > Subject: RE: [PATCH v3][Patch 2/4] MdePkg/UefiDevicePathLib: Add > DevPathFromTextDns and DevPathToTextDns libraries >=20 > Hi Jiaxin, >=20 > Shall we check the return value of CreateDeviceNode in > DevPathFromTextDns to make sure we don't use NULL pointer? > I see many internal functions DevPathFromText** in DevicePathFromText.c > NOT check this. Any particular reason we don't need this? >=20 > Thanks, > Ting >=20 > -----Original Message----- > From: Wu, Jiaxin > Sent: Thursday, August 03, 2017 8:20 PM > To: edk2-devel@lists.01.org > Cc: Ye, Ting ; Fu, Siyuan ; Wu, > Jiaxin > Subject: [PATCH v3][Patch 2/4] MdePkg/UefiDevicePathLib: Add > DevPathFromTextDns and DevPathToTextDns libraries >=20 > V3: > * Fix the bug in DevPathFromTextDns() >=20 > V2: > * Add no IP instance case check. >=20 > Cc: Ye Ting > Cc: Fu Siyuan > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Wu Jiaxin > Reviewed-by: Fu Siyuan > --- > .../Library/UefiDevicePathLib/DevicePathFromText.c | 90 > ++++++++++++++++++++++ > .../Library/UefiDevicePathLib/DevicePathToText.c | 46 +++++++++++ > 2 files changed, 136 insertions(+) >=20 > diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c > b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c > index f50c11c..0fb703b 100644 > --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c > +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c > @@ -2723,10 +2723,99 @@ DevPathFromTextBluetoothLE ( > ); > return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp; } >=20 > /** > + Converts a text device path node to DNS device path structure. > + > + @param TextDeviceNode The input Text device path node. > + > + @return A pointer to the newly-created DNS device path structure. > + > +**/ > +EFI_DEVICE_PATH_PROTOCOL * > +DevPathFromTextDns ( > + IN CHAR16 *TextDeviceNode > + ) > +{ > + CHAR16 *DeviceNodeStr; > + CHAR16 *DeviceNodeStrPtr; > + UINT32 DnsServerIpCount; > + UINT16 DnsDeviceNodeLength; > + DNS_DEVICE_PATH *DnsDeviceNode; > + UINT32 DnsServerIpIndex; > + CHAR16 *DnsServerIp; > + > + > + // > + // Count the DNS server address number. > + // > + DeviceNodeStr =3D UefiDevicePathLibStrDuplicate (TextDeviceNode); if > + (DeviceNodeStr =3D=3D NULL) { > + return NULL; > + } > + > + DeviceNodeStrPtr =3D DeviceNodeStr; > + > + DnsServerIpCount =3D 0; > + while (DeviceNodeStrPtr !=3D NULL && *DeviceNodeStrPtr !=3D L'\0') { > + GetNextParamStr (&DeviceNodeStrPtr); > + DnsServerIpCount ++; > + } > + > + FreePool (DeviceNodeStr); > + DeviceNodeStr =3D NULL; > + > + // > + // One or more instances of the DNS server address in EFI_IP_ADDRESS, > + // otherwise, NULL will be returned. > + // > + if (DnsServerIpCount =3D=3D 0) { > + return NULL; > + } > + > + // > + // Create the DNS DeviceNode. > + // > + DnsDeviceNodeLength =3D (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) > + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS)); > + DnsDeviceNode =3D (DNS_DEVICE_PATH *) CreateDeviceNode ( > + MESSAGING_DEVICE_PATH, > + MSG_DNS_DP, > + DnsDeviceNodeLength > + ); > + > + // > + // Confirm the DNS server address is IPv4 or IPv6 type. > + // > + DeviceNodeStrPtr =3D TextDeviceNode; > + while (!IS_NULL (*DeviceNodeStrPtr)) { > + if (*DeviceNodeStrPtr =3D=3D L'.') { > + DnsDeviceNode->IsIPv6 =3D 0x00; > + break; > + } > + > + if (*DeviceNodeStrPtr =3D=3D L':') { > + DnsDeviceNode->IsIPv6 =3D 0x01; > + break; > + } > + > + DeviceNodeStrPtr++; > + } > + > + for (DnsServerIpIndex =3D 0; DnsServerIpIndex < DnsServerIpCount; > DnsServerIpIndex++) { > + DnsServerIp =3D GetNextParamStr (&TextDeviceNode); > + if (DnsDeviceNode->IsIPv6 =3D=3D 0x00) { > + StrToIpv4Address (DnsServerIp, NULL, &(DnsDeviceNode- > >DnsServerIp[DnsServerIpIndex].v4), NULL); > + } else { > + StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode- > >DnsServerIp[DnsServerIpIndex].v6), NULL); > + } > + } > + > + return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode; } > + > +/** > Converts a text device path node to URI device path structure. >=20 > @param TextDeviceNode The input Text device path node. >=20 > @return A pointer to the newly-created URI device path structure. > @@ -3395,10 +3484,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED > DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP > {L"UsbTestAndMeasurement", > DevPathFromTextUsbTestAndMeasurement }, > {L"UsbWwid", DevPathFromTextUsbWwid }, > {L"Unit", DevPathFromTextUnit }, > {L"iSCSI", DevPathFromTextiSCSI }, > {L"Vlan", DevPathFromTextVlan }, > + {L"Dns", DevPathFromTextDns }, > {L"Uri", DevPathFromTextUri }, > {L"Bluetooth", DevPathFromTextBluetooth }, > {L"Wi-Fi", DevPathFromTextWiFi }, > {L"BluetoothLE", DevPathFromTextBluetoothLE }, > {L"MediaPath", DevPathFromTextMediaPath }, > diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c > b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c > index b8d9491..63542db 100644 > --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c > +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c > @@ -1695,10 +1695,55 @@ DevPathToTextBluetoothLE ( > BluetoothLE->Address.Type > ); > } >=20 > /** > + Converts a DNS device path structure to its string representative. > + > + @param Str The string representative of input device. > + @param DevPath The input device path structure. > + @param DisplayOnly If DisplayOnly is TRUE, then the shorter text > representation > + of the display node is used, where applicable. = If DisplayOnly > + is FALSE, then the longer text representation o= f the display > node > + is used. > + @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut > forms of text > + representation for a device node can be used, w= here > applicable. > + > +**/ > +VOID > +DevPathToTextDns ( > + IN OUT POOL_PRINT *Str, > + IN VOID *DevPath, > + IN BOOLEAN DisplayOnly, > + IN BOOLEAN AllowShortcuts > + ) > +{ > + DNS_DEVICE_PATH *DnsDevPath; > + UINT32 DnsServerIpCount; > + UINT32 DnsServerIpIndex; > + > + DnsDevPath =3D DevPath; > + DnsServerIpCount =3D (UINT32) (DevicePathNodeLength(DnsDevPath) - > + sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / > + sizeof (EFI_IP_ADDRESS); > + > + UefiDevicePathLibCatPrint (Str, L"Dns("); > + > + for (DnsServerIpIndex =3D 0; DnsServerIpIndex < DnsServerIpCount; > DnsServerIpIndex++) { > + if (DnsDevPath->IsIPv6 =3D=3D 0x00) { > + CatIPv4Address (Str, &(DnsDevPath- > >DnsServerIp[DnsServerIpIndex].v4)); > + } else { > + CatIPv6Address (Str, &(DnsDevPath- > >DnsServerIp[DnsServerIpIndex].v6)); > + } > + > + if (DnsServerIpIndex < DnsServerIpCount - 1) { > + UefiDevicePathLibCatPrint (Str, L","); > + } > + } > + > + UefiDevicePathLibCatPrint (Str, L")"); } > + > +/** > Converts a URI device path structure to its string representative. >=20 > @param Str The string representative of input device. > @param DevPath The input device path structure. > @param DisplayOnly If DisplayOnly is TRUE, then the shorter text > representation > @@ -2223,10 +2268,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED const > DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLib > {MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, > DevPathToTextInfiniBand }, > {MESSAGING_DEVICE_PATH, MSG_UART_DP, > DevPathToTextUart }, > {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, > DevPathToTextVendor }, > {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, > DevPathToTextiSCSI }, > {MESSAGING_DEVICE_PATH, MSG_VLAN_DP, > DevPathToTextVlan }, > + {MESSAGING_DEVICE_PATH, MSG_DNS_DP, > DevPathToTextDns }, > {MESSAGING_DEVICE_PATH, MSG_URI_DP, > DevPathToTextUri }, > {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP, > DevPathToTextBluetooth }, > {MESSAGING_DEVICE_PATH, MSG_WIFI_DP, > DevPathToTextWiFi }, > {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_LE_DP, > DevPathToTextBluetoothLE }, > {MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, > DevPathToTextHardDrive }, > -- > 1.9.5.msysgit.1