diff options
author | Michael Brown | 2016-01-21 17:24:16 +0100 |
---|---|---|
committer | Michael Brown | 2016-01-21 19:00:33 +0100 |
commit | f0e9e55442023c2f18e62cf74fe9098e0a6f5347 (patch) | |
tree | bb6ad3c5c63bbec368795b86d3e4f897a0421381 /src/net/udp/tftp.c | |
parent | [ocsp] Avoid including a double path separator in request URI (diff) | |
download | ipxe-f0e9e55442023c2f18e62cf74fe9098e0a6f5347.tar.gz ipxe-f0e9e55442023c2f18e62cf74fe9098e0a6f5347.tar.xz ipxe-f0e9e55442023c2f18e62cf74fe9098e0a6f5347.zip |
[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 <mcb30@ipxe.org>
Diffstat (limited to 'src/net/udp/tftp.c')
-rw-r--r-- | src/net/udp/tftp.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c index f3cb3434..4255472e 100644 --- a/src/net/udp/tftp.c +++ b/src/net/udp/tftp.c @@ -325,7 +325,7 @@ void tftp_set_mtftp_port ( unsigned int port ) { * @ret rc Return status code */ static int tftp_send_rrq ( struct tftp_request *tftp ) { - const char *path = tftp->uri->path; + const char *path = ( tftp->uri->path + 1 /* skip '/' */ ); struct tftp_rrq *rrq; size_t len; struct io_buffer *iobuf; @@ -1067,6 +1067,8 @@ static int tftp_core_open ( struct interface *xfer, struct uri *uri, return -EINVAL; if ( ! uri->path ) return -EINVAL; + if ( uri->path[0] != '/' ) + return -EINVAL; /* Allocate and populate TFTP structure */ tftp = zalloc ( sizeof ( *tftp ) ); |