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