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