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