Blame SOURCES/0212-Normalize-slashes-in-tftp-paths.patch

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