dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone
27a4da
From 34dbd541e7baea7391f11377d83db707568a8d91 Mon Sep 17 00:00:00 2001
23d2ea
From: Lenny Szubowicz <lszubowi@redhat.com>
23d2ea
Date: Mon, 29 Aug 2016 11:04:48 -0400
27a4da
Subject: [PATCH 212/260] Normalize slashes in tftp paths.
23d2ea
23d2ea
Some tftp servers do not handle multiple consecutive slashes correctly;
23d2ea
this patch avoids sending tftp requests with non-normalized paths.
23d2ea
23d2ea
Signed-off-by: Peter Jones <pjones@redhat.com>
23d2ea
---
23d2ea
 grub-core/net/tftp.c | 28 +++++++++++++++++++++++++---
23d2ea
 1 file changed, 25 insertions(+), 3 deletions(-)
23d2ea
23d2ea
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
27a4da
index 22a4debdc..8632339de 100644
23d2ea
--- a/grub-core/net/tftp.c
23d2ea
+++ b/grub-core/net/tftp.c
23d2ea
@@ -300,6 +300,25 @@ destroy_pq (tftp_data_t data)
23d2ea
   grub_priority_queue_destroy (data->pq);
23d2ea
 }
23d2ea
 
23d2ea
+/* Create a normalized copy of the filename.
23d2ea
+   Compress any string of consecutive forward slashes to a single forward
23d2ea
+   slash. */
23d2ea
+static void
23d2ea
+grub_normalize_filename (char *normalized, const char *filename)
23d2ea
+{
23d2ea
+  char *dest = normalized;
23d2ea
+  char *src = filename;
23d2ea
+
23d2ea
+  while (*src != '\0')
23d2ea
+    {
23d2ea
+      if (src[0] == '/' && src[1] == '/')
23d2ea
+	src++;
23d2ea
+      else
23d2ea
+	*dest++ = *src++;
23d2ea
+    }
23d2ea
+  *dest = '\0';
23d2ea
+}
23d2ea
+
23d2ea
 static grub_err_t
23d2ea
 tftp_open (struct grub_file *file, const char *filename)
23d2ea
 {
23d2ea
@@ -334,9 +353,12 @@ tftp_open (struct grub_file *file, const char *filename)
23d2ea
   rrqlen = 0;
23d2ea
 
23d2ea
   tftph->opcode = grub_cpu_to_be16 (TFTP_RRQ);
23d2ea
-  grub_strcpy (rrq, filename);
23d2ea
-  rrqlen += grub_strlen (filename) + 1;
23d2ea
-  rrq += grub_strlen (filename) + 1;
23d2ea
+
23d2ea
+  /* Copy and normalize the filename to work-around issues on some tftp
23d2ea
+     servers when file names are being matched for remapping. */
23d2ea
+  grub_normalize_filename (rrq, filename);
23d2ea
+  rrqlen += grub_strlen (rrq) + 1;
23d2ea
+  rrq += grub_strlen (rrq) + 1;
23d2ea
 
23d2ea
   grub_strcpy (rrq, "octet");
23d2ea
   rrqlen += grub_strlen ("octet") + 1;
23d2ea
-- 
27a4da
2.13.0
23d2ea