Blame SOURCES/0129-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Javier Martinez Canillas <javierm@redhat.com>
8e15ce
Date: Tue, 2 Jun 2020 13:25:01 +0200
8e15ce
Subject: [PATCH] http: Prepend prefix when the HTTP path is relative as done
8e15ce
 in efi/http
8e15ce
8e15ce
There are two different HTTP drivers that can be used when requesting an
8e15ce
HTTP resource: the efi/http that uses the EFI_HTTP_PROTOCOL and the http
8e15ce
that uses GRUB's HTTP and TCP/IP implementation.
8e15ce
8e15ce
The efi/http driver appends a prefix that is defined in the variable
8e15ce
http_path, but the http driver doesn't.
8e15ce
8e15ce
So using this driver and attempting to fetch a resource using a relative
8e15ce
path fails.
8e15ce
8e15ce
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
8e15ce
---
8e15ce
 grub-core/net/http.c | 9 ++++++++-
8e15ce
 1 file changed, 8 insertions(+), 1 deletion(-)
8e15ce
8e15ce
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
b35c50
index b52b558d63..7f878b5615 100644
8e15ce
--- a/grub-core/net/http.c
8e15ce
+++ b/grub-core/net/http.c
8e15ce
@@ -501,13 +501,20 @@ http_open (struct grub_file *file, const char *filename)
8e15ce
 {
8e15ce
   grub_err_t err;
8e15ce
   struct http_data *data;
8e15ce
+  const char *http_path;
8e15ce
 
8e15ce
   data = grub_zalloc (sizeof (*data));
8e15ce
   if (!data)
8e15ce
     return grub_errno;
8e15ce
   file->size = GRUB_FILE_SIZE_UNKNOWN;
8e15ce
 
8e15ce
-  data->filename = grub_strdup (filename);
8e15ce
+  /* If path is relative, prepend http_path */
8e15ce
+  http_path = grub_env_get ("http_path");
8e15ce
+  if (http_path && filename[0] != '/')
8e15ce
+    data->filename = grub_xasprintf ("%s/%s", http_path, filename);
8e15ce
+  else
8e15ce
+    data->filename = grub_strdup (filename);
8e15ce
+
8e15ce
   if (!data->filename)
8e15ce
     {
8e15ce
       grub_free (data);