grub2/0116-Normalize-slashes-in-t...

77 lines
2.4 KiB
Diff
Raw Normal View History

From 7de6bfc149f657a997968d29e1d557f6f4e61c97 Mon Sep 17 00:00:00 2001
From: Lenny Szubowicz <lszubowi@redhat.com>
Date: Mon, 29 Aug 2016 11:04:48 -0400
Subject: [PATCH 116/225] Normalize slashes in tftp paths.
Some tftp servers do not handle multiple consecutive slashes correctly;
this patch avoids sending tftp requests with non-normalized paths.
Signed-off-by: Peter Jones <pjones@redhat.com>
(This was previously 06dce837a - Normalize slashes in tftp paths)
This commit also merges:
9b00cee6e - Fix malformed tftp packets
0088-Normalize-slashes-in-tftp-paths.patch collapses multiple contiguous
slashes in a filename into one slash in the tftp packet filename field.
However, the packet buffer pointer is advanced using the original name.
This leaves unitialized data between the name field and the type field
leading to tftp errors. Use the length of the normalized name to avoid
this.
Signed-off-by: Mark Salter <msalter@redhat.com>
---
grub-core/net/tftp.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
index 7d90bf66e..dd4ce6b23 100644
--- 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;
+ const char *src = filename;
+
+ 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)
{
@@ -337,9 +356,12 @@ tftp_open (struct grub_file *file, const char *filename)
rrqlen = 0;
tftph->opcode = grub_cpu_to_be16_compile_time (TFTP_RRQ);
- grub_strcpy (rrq, filename);
- rrqlen += grub_strlen (filename) + 1;
- rrq += grub_strlen (filename) + 1;
+
+ /* 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);
+ rrqlen += grub_strlen (rrq) + 1;
+ rrq += grub_strlen (rrq) + 1;
grub_strcpy (rrq, "octet");
rrqlen += grub_strlen ("octet") + 1;
--
2.14.3