From a3252028d7be5c78254fc4a940186588c2607a28 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 1 Feb 2011 02:56:06 +0000 Subject: [PATCH 1/3] [autoboot] Avoid using uri_dup() for constructed TFTP URI uri_dup() chokes on duplicating a URI with a path that does not begin with a slash. Signed-off-by: Michael Brown --- src/usr/autoboot.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 91f1c6e8..20c67f34 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -66,8 +66,9 @@ static struct net_device * find_boot_netdev ( void ) { */ static struct uri * parse_next_server_and_filename ( struct in_addr next_server, const char *filename ) { + char buf[ 23 /* "tftp://xxx.xxx.xxx.xxx/" */ + strlen ( filename ) + + 1 /* NUL */ ]; struct uri *uri; - struct uri *tmp; /* Parse filename */ uri = parse_uri ( filename ); @@ -81,11 +82,10 @@ static struct uri * parse_next_server_and_filename ( struct in_addr next_server, * significant for TFTP. */ if ( ! uri_is_absolute ( uri ) ) { - tmp = uri; - tmp->scheme = "tftp"; - tmp->host = inet_ntoa ( next_server ); - uri = uri_dup ( tmp ); - uri_put ( tmp ); + uri_put ( uri ); + snprintf ( buf, sizeof ( buf ), "tftp://%s/%s", + inet_ntoa ( next_server ), filename ); + uri = parse_uri ( filename ); if ( ! uri ) return NULL; } From d77b183f103227bb67b300017add920ab14f6912 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 1 Feb 2011 04:25:19 +0000 Subject: [PATCH 2/3] [uri] Add uri_has_path() Signed-off-by: Michael Brown --- src/include/ipxe/uri.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/include/ipxe/uri.h b/src/include/ipxe/uri.h index cb0898e4..b7b8b441 100644 --- a/src/include/ipxe/uri.h +++ b/src/include/ipxe/uri.h @@ -113,6 +113,16 @@ static inline int uri_is_absolute ( struct uri *uri ) { return ( uri->scheme != NULL ); } +/** + * URI has a path + * + * @v uri URI + * @ret has_path URI has a path + */ +static inline int uri_has_path ( struct uri *uri ) { + return ( uri->path && ( uri->path[0] != '\0' ) ); +} + /** * URI has an absolute path * From 88b8aa0f6554d6284a72e8e7b8c68572e35e3a61 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 1 Feb 2011 04:25:38 +0000 Subject: [PATCH 3/3] [autoboot] Cope properly with empty DHCP filenames This (hopefully) fixes a regression introduced in commit e088892 ("[autoboot] Connect SAN disk during a filename boot, if applicable"). Signed-off-by: Michael Brown --- src/usr/autoboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 20c67f34..bb7d692e 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -81,11 +81,11 @@ static struct uri * parse_next_server_and_filename ( struct in_addr next_server, * filenames with and without initial slashes, which is * significant for TFTP. */ - if ( ! uri_is_absolute ( uri ) ) { + if ( next_server.s_addr && filename[0] && ! uri_is_absolute ( uri ) ) { uri_put ( uri ); snprintf ( buf, sizeof ( buf ), "tftp://%s/%s", inet_ntoa ( next_server ), filename ); - uri = parse_uri ( filename ); + uri = parse_uri ( buf ); if ( ! uri ) return NULL; } @@ -130,7 +130,7 @@ int uriboot ( struct uri *filename, struct uri *root_path ) { } /* Treat empty URIs as absent */ - if ( filename && ( ! filename->path ) ) + if ( filename && ( ! uri_has_path ( filename ) ) ) filename = NULL; if ( root_path && ( ! uri_is_absolute ( root_path ) ) ) root_path = NULL;