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