2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-12-01 22:17:43 +00:00
|
|
|
From: Lenny Szubowicz <lszubowi@redhat.com>
|
|
|
|
Date: Mon, 29 Aug 2016 11:04:48 -0400
|
2018-07-10 18:39:10 +00:00
|
|
|
Subject: [PATCH] Normalize slashes in tftp paths.
|
2016-12-01 22:17:43 +00:00
|
|
|
|
|
|
|
Some tftp servers do not handle multiple consecutive slashes correctly;
|
|
|
|
this patch avoids sending tftp requests with non-normalized paths.
|
|
|
|
|
2019-07-16 09:23:51 +00:00
|
|
|
Signed-off-by: Lenny Szubowicz <lszubowi@redhat.com>
|
|
|
|
[msalter: fix malformed tftp packets]
|
|
|
|
Signed-off-by: Mark Salter <msalter@redhat.com>
|
2016-12-01 22:17:43 +00:00
|
|
|
---
|
2019-07-16 09:23:51 +00:00
|
|
|
grub-core/net/tftp.c | 28 +++++++++++++++++++++++++---
|
|
|
|
1 file changed, 25 insertions(+), 3 deletions(-)
|
2016-12-01 22:17:43 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
|
2020-08-21 09:11:22 +00:00
|
|
|
index a5c5038130a..e6d831f1bc9 100644
|
2016-12-01 22:17:43 +00:00
|
|
|
--- a/grub-core/net/tftp.c
|
|
|
|
+++ b/grub-core/net/tftp.c
|
|
|
|
@@ -300,6 +300,25 @@ destroy_pq (tftp_data_t data)
|
|
|
|
grub_priority_queue_destroy (data->pq);
|
|
|
|
}
|
|
|
|
|
|
|
|
+/* Create a normalized copy of the filename.
|
|
|
|
+ Compress any string of consecutive forward slashes to a single forward
|
|
|
|
+ slash. */
|
|
|
|
+static void
|
|
|
|
+grub_normalize_filename (char *normalized, const char *filename)
|
|
|
|
+{
|
|
|
|
+ char *dest = normalized;
|
2018-01-17 22:04:09 +00:00
|
|
|
+ char *src = filename;
|
2016-12-01 22:17:43 +00:00
|
|
|
+
|
|
|
|
+ while (*src != '\0')
|
|
|
|
+ {
|
|
|
|
+ if (src[0] == '/' && src[1] == '/')
|
|
|
|
+ src++;
|
|
|
|
+ else
|
|
|
|
+ *dest++ = *src++;
|
|
|
|
+ }
|
|
|
|
+ *dest = '\0';
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static grub_err_t
|
|
|
|
tftp_open (struct grub_file *file, const char *filename)
|
|
|
|
{
|
2019-07-16 09:23:51 +00:00
|
|
|
@@ -337,9 +356,12 @@ tftp_open (struct grub_file *file, const char *filename)
|
2016-12-01 22:17:43 +00:00
|
|
|
rrqlen = 0;
|
|
|
|
|
|
|
|
tftph->opcode = grub_cpu_to_be16_compile_time (TFTP_RRQ);
|
|
|
|
- grub_strcpy (rrq, filename);
|
2019-07-16 09:23:51 +00:00
|
|
|
- rrqlen += grub_strlen (filename) + 1;
|
|
|
|
- rrq += grub_strlen (filename) + 1;
|
2016-12-01 22:17:43 +00:00
|
|
|
+
|
|
|
|
+ /* Copy and normalize the filename to work-around issues on some tftp
|
|
|
|
+ servers when file names are being matched for remapping. */
|
|
|
|
+ grub_normalize_filename (rrq, filename);
|
2019-07-16 09:23:51 +00:00
|
|
|
+ rrqlen += grub_strlen (rrq) + 1;
|
|
|
|
+ rrq += grub_strlen (rrq) + 1;
|
2016-12-01 22:17:43 +00:00
|
|
|
|
2019-07-16 09:23:51 +00:00
|
|
|
grub_strcpy (rrq, "octet");
|
|
|
|
rrqlen += grub_strlen ("octet") + 1;
|