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