From f0e9e55442023c2f18e62cf74fe9098e0a6f5347 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 21 Jan 2016 16:24:16 +0000 Subject: [tftp] Mangle initial slash on TFTP URIs TFTP URIs are intrinsically problematic, since: - TFTP servers may use either normal slashes or backslashes as a directory separator, - TFTP servers allow filenames to be specified using relative paths (with no initial directory separator), - TFTP filenames present in a DHCP filename field may use special characters such as "?" or "#" that prevent parsing as a generic URI. As of commit 7667536 ("[uri] Refactor URI parsing and formatting"), we have directly constructed TFTP URIs from DHCP next-server and filename pairs, avoiding the generic URI parser. This eliminated the problems related to special characters, but indirectly made it impossible to parse a "tftp://..." URI string into a TFTP URI with a non-absolute path. Re-introduce the convention of requiring an extra slash in a "tftp://..." URI string in order to specify a TFTP URI with an initial slash in the filename. For example: tftp://192.168.0.1/boot/pxelinux.0 => RRQ "boot/pxelinux.0" tftp://192.168.0.1//boot/pxelinux.0 => RRQ "/boot/pxelinux.0" This is ugly, but there seems to be no other sensible way to provide the ability to specify all possible TFTP filenames. A side-effect of this change is that format_uri() will no longer add a spurious initial "/" when formatting a relative URI string. This improves the console output when fetching an image specified via a relative URI. Signed-off-by: Michael Brown --- src/tests/uri_test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tests') diff --git a/src/tests/uri_test.c b/src/tests/uri_test.c index 42c1c43d..a068ab33 100644 --- a/src/tests/uri_test.c +++ b/src/tests/uri_test.c @@ -713,9 +713,9 @@ static struct uri_pxe_test uri_pxe_absolute_path = { { .scheme = "tftp", .host = "192.168.0.2", - .path = "/absolute/path", + .path = "//absolute/path", }, - "tftp://192.168.0.2/absolute/path", + "tftp://192.168.0.2//absolute/path", }; /** PXE URI with relative path */ @@ -731,7 +731,7 @@ static struct uri_pxe_test uri_pxe_relative_path = { { .scheme = "tftp", .host = "192.168.0.3", - .path = "relative/path", + .path = "/relative/path", }, "tftp://192.168.0.3/relative/path", }; @@ -749,7 +749,7 @@ static struct uri_pxe_test uri_pxe_icky = { { .scheme = "tftp", .host = "10.0.0.6", - .path = "C:\\tftpboot\\icky#path", + .path = "/C:\\tftpboot\\icky#path", }, "tftp://10.0.0.6/C%3A\\tftpboot\\icky%23path", }; @@ -769,9 +769,9 @@ static struct uri_pxe_test uri_pxe_port = { .scheme = "tftp", .host = "192.168.0.1", .port = "4069", - .path = "/another/path", + .path = "//another/path", }, - "tftp://192.168.0.1:4069/another/path", + "tftp://192.168.0.1:4069//another/path", }; /** Current working URI test */ -- cgit v1.2.3-55-g7522