From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org 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 5D004210C669C for ; Tue, 31 Jul 2018 18:56:07 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2018 18:56:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,430,1526367600"; d="scan'208";a="250658792" Received: from jiaxinwu-mobl.ccr.corp.intel.com ([10.239.192.149]) by fmsmga006.fm.intel.com with ESMTP; 31 Jul 2018 18:54:49 -0700 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Ye Ting , Fu Siyuan , Laszlo Ersek , Wu Jiaxin Date: Wed, 1 Aug 2018 09:54:42 +0800 Message-Id: <20180801015442.6932-1-Jiaxin.wu@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 Subject: [Patch] NetworkPkg/HttpDxe: Stripped square brackets in IPv6 expressed HostName. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2018 01:56:08 -0000 In URI, the colon (:) is used to terminate the HostName path before a port number. However, if HostName is expressed as IPv6 format, colon characters in IPv6 addresses will conflict with the colon before port number. To alleviate this conflict in URI, the IPv6 expressed HostName are enclosed in square brackets ([]). To record the real IPv6 HostName, square brackets should be stripped. Cc: Ye Ting Cc: Fu Siyuan Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/HttpDxe/HttpImpl.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index 17deceb395..e05ee9344b 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -403,14 +403,25 @@ EfiHttpRequest ( Status = HttpParseUrl (Url, (UINT32) AsciiStrLen (Url), FALSE, &UrlParser); if (EFI_ERROR (Status)) { goto Error1; } - HostName = NULL; - Status = HttpUrlGetHostName (Url, UrlParser, &HostName); + Status = HttpUrlGetHostName (Url, UrlParser, &HostName); if (EFI_ERROR (Status)) { - goto Error1; + goto Error1; + } + + if (HttpInstance->LocalAddressIsIPv6 && AsciiStrSize (HostName) > 2 && + HostName[0] == '[' && *(HostName + (AsciiStrSize (HostName) - 2)) == ']') { + // + // HostName format is expressed as IPv6, so, remove '[' and ']'. + // + HostNameSize = AsciiStrSize (HostName) - 2; + + CopyMem (HostName, HostName + 1, HostNameSize - 1); + + *(HostName + HostNameSize - 1) = '\0'; } Status = HttpUrlGetPort (Url, UrlParser, &RemotePort); if (EFI_ERROR (Status)) { if (HttpInstance->UseHttps) { -- 2.17.1.windows.2