5 Star 0 Fork 16

OpenCloudOS Stream/grub2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0242-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch 3.94 KB
一键复制 编辑 原始数据 按行查看 历史
nilusyi 提交于 2024-04-07 16:45 . update patches
From 87aca3738c9c8168e43349910eed08ebbc779a77 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Thu, 5 Mar 2020 16:21:58 +0100
Subject: [PATCH 242/272] efi/http: Enclose literal IPv6 addresses in square
brackets
According to RFC 2732 (https://www.ietf.org/rfc/rfc2732.txt), literal IPv6
addresses must be enclosed in square brackets. But GRUB currently does not
do this and is causing HTTP servers to send Bad Request (400) responses.
For example, the following is the HTTP stream when fetching a config file:
HEAD /EFI/BOOT/grub.cfg HTTP/1.1
Host: 2000:dead:beef:a::1
Accept: */*
User-Agent: UefiHttpBoot/1.0
HTTP/1.1 400 Bad Request
Date: Thu, 05 Mar 2020 14:46:02 GMT
Server: Apache/2.4.41 (Fedora) OpenSSL/1.1.1d
Connection: close
Content-Type: text/html; charset=iso-8859-1
and after enclosing the IPv6 address the HTTP request is successful:
HEAD /EFI/BOOT/grub.cfg HTTP/1.1
Host: [2000:dead:beef:a::1]
Accept: */*
User-Agent: UefiHttpBoot/1.0
HTTP/1.1 200 OK
Date: Thu, 05 Mar 2020 14:48:04 GMT
Server: Apache/2.4.41 (Fedora) OpenSSL/1.1.1d
Last-Modified: Thu, 27 Feb 2020 17:45:58 GMT
ETag: "206-59f924b24b1da"
Accept-Ranges: bytes
Content-Length: 518
Resolves: rhbz#1732765
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/net/efi/http.c | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c
index b20e99100..5b4ebfb99 100644
--- a/grub-core/net/efi/http.c
+++ b/grub-core/net/efi/http.c
@@ -159,13 +159,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https,
grub_efi_status_t status;
grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
char *url = NULL;
-
- request_headers[0].field_name = (grub_efi_char8_t *)"Host";
- request_headers[0].field_value = (grub_efi_char8_t *)server;
- request_headers[1].field_name = (grub_efi_char8_t *)"Accept";
- request_headers[1].field_value = (grub_efi_char8_t *)"*/*";
- request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent";
- request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0";
+ char *hostname = NULL;
{
grub_efi_ipv6_address_t address;
@@ -176,10 +170,24 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https,
grub_size_t sz;
if (grub_efi_string_to_ip6_address (server, &address, &rest) && *rest == 0)
- url = grub_xasprintf ("%s://[%s]%s", protocol, server, name);
+ {
+ hostname = grub_xasprintf ("[%s]", server);
+ if (!hostname)
+ return GRUB_ERR_OUT_OF_MEMORY;
+
+ server = hostname;
+
+ url = grub_xasprintf ("%s://%s%s", protocol, server, name);
+ if (!url)
+ {
+ grub_free (hostname);
+ return GRUB_ERR_OUT_OF_MEMORY;
+ }
+ }
else
+ {
url = grub_xasprintf ("%s://%s%s", protocol, server, name);
-
+ }
if (!url)
{
return grub_errno;
@@ -204,6 +212,13 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https,
request_data.url = ucs2_url;
}
+ request_headers[0].field_name = (grub_efi_char8_t *)"Host";
+ request_headers[0].field_value = (grub_efi_char8_t *)server;
+ request_headers[1].field_name = (grub_efi_char8_t *)"Accept";
+ request_headers[1].field_value = (grub_efi_char8_t *)"*/*";
+ request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent";
+ request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0";
+
request_data.method = (headeronly > 0) ? GRUB_EFI_HTTPMETHODHEAD : GRUB_EFI_HTTPMETHODGET;
request_message.data.request = &request_data;
@@ -233,6 +248,9 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https,
status = http->request (http, &request_token);
+ if (hostname)
+ grub_free (hostname);
+
if (status != GRUB_EFI_SUCCESS)
{
b->close_event (request_token.event);
--
2.41.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opencloudos-stream/grub2.git
git@gitee.com:opencloudos-stream/grub2.git
opencloudos-stream
grub2
grub2
master

搜索帮助