http: Prepend prefix when the HTTP path is relative
authorJavier Martinez Canillas <javierm@redhat.com>
Mon, 9 Jan 2023 23:30:43 +0000 (18:30 -0500)
committerFelix Zielcke <fzielcke@z-51.de>
Mon, 15 Jul 2024 15:05:20 +0000 (17:05 +0200)
There are two different HTTP drivers that can be used when requesting an
HTTP resource: the efi/http that uses the EFI_HTTP_PROTOCOL and the http
that uses GRUB's HTTP and TCP/IP implementation.

The efi/http driver appends a prefix that is defined in the variable
http_path, but the http driver doesn't.  So using this driver and
attempting to fetch a resource using a relative path fails.  Match the
behavior of efi/http.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Co-authored-by: Robbie Harwood <rharwood@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Gbp-Pq: Topic network
Gbp-Pq: Name http-prepend-prefix-when-the-http-path-is-relative.patch

grub-core/net/http.c

index f63f8b9226b5a007206fb45a2cbe1d2e2c103c89..000f9db95a0b191e7a72b0c0c2b611a70fc216c2 100644 (file)
@@ -16,6 +16,7 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <grub/env.h>
 #include <grub/misc.h>
 #include <grub/net/tcp.h>
 #include <grub/net/ip.h>
@@ -501,13 +502,20 @@ http_open (struct grub_file *file, const char *filename)
 {
   grub_err_t err;
   struct http_data *data;
+  const char *http_path;
 
   data = grub_zalloc (sizeof (*data));
   if (!data)
     return grub_errno;
   file->size = GRUB_FILE_SIZE_UNKNOWN;
 
-  data->filename = grub_strdup (filename);
+  /* If path is relative, prepend http_path */
+  http_path = grub_env_get ("http_path");
+  if (http_path && filename[0] != '/')
+    data->filename = grub_xasprintf ("%s/%s", http_path, filename);
+  else
+    data->filename = grub_strdup (filename);
+
   if (!data->filename)
     {
       grub_free (data);