[ipxe-devel] [PATCH] Fix loading tftp file from pxe bios call
Frediano Ziglio
frediano.ziglio at citrix.com
Mon May 13 14:59:39 UTC 2013
From 1827c48034d2387819629c4b28d7c2910b5d889b Mon Sep 17 00:00:00 2001
From: Frediano Ziglio <frediano.ziglio at citrix.com>
Date: Mon, 13 May 2013 15:58:32 +0100
Subject: [PATCH] Fix loading tftp file from pxe bios call
If filename contained '#' tftp does not load correctly file cause url was not
quoted correctly.
This patch actually fix two paths in the code that require quoting filename:
- loading file from dhcp;
- loading file from PXE calls.
Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com>
---
src/arch/i386/interface/pxe/pxe_tftp.c | 13 ++++++++++---
src/usr/autoboot.c | 8 +++++---
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/arch/i386/interface/pxe/pxe_tftp.c b/src/arch/i386/interface/pxe/pxe_tftp.c
index f4801ba..90599fd 100644
--- a/src/arch/i386/interface/pxe/pxe_tftp.c
+++ b/src/arch/i386/interface/pxe/pxe_tftp.c
@@ -31,6 +31,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <byteswap.h>
#include <ipxe/uaccess.h>
#include <ipxe/in.h>
+#include <ipxe/uri.h>
+#include <ipxe/vsprintf.h>
#include <ipxe/tftp.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
@@ -174,6 +176,7 @@ static int pxe_tftp_open ( uint32_t ipaddress, unsigned int port,
const unsigned char *filename, size_t blksize,
int sizeonly ) {
char uri_string[PXE_TFTP_URI_LEN];
+ ssize_t len;
struct in_addr address;
int rc;
@@ -189,10 +192,14 @@ static int pxe_tftp_open ( uint32_t ipaddress, unsigned int port,
address.s_addr = ipaddress;
if ( ! port )
port = htons ( TFTP_PORT );
- snprintf ( uri_string, sizeof ( uri_string ), "tftp%s://%s:%d%s%s",
+ len = snprintf ( uri_string, sizeof ( uri_string ), "tftp%s://%s:%d%s",
sizeonly ? "size" : "", inet_ntoa ( address ),
- ntohs ( port ), ( ( filename[0] == '/' ) ? "" : "/" ),
- filename );
+ ntohs ( port ), ( ( filename[0] == '/' ) ? "" : "/" ) );
+ len += uri_encode( (const char *) filename, uri_string + len, sizeof ( uri_string ) - len, URI_PATH);
+ if ( len >= (ssize_t) sizeof ( uri_string ) ) {
+ return -ENAMETOOLONG;
+ }
+ uri_string[len] = 0;
DBG ( " %s", uri_string );
/* Open PXE TFTP connection */
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index b2d288e..4359dfe 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -91,9 +91,10 @@ 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 )
+ char buf[ 23 /* "tftp://xxx.xxx.xxx.xxx/" */ + 3 * strlen ( filename )
+ 1 /* NUL */ ];
struct uri *uri;
+ int len;
/* Parse filename */
uri = parse_uri ( filename );
@@ -108,8 +109,9 @@ static struct uri * parse_next_server_and_filename ( struct in_addr next_server,
*/
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 );
+ len = snprintf ( buf, sizeof ( buf ), "tftp://%s%s",
+ inet_ntoa ( next_server ), ( filename[0] == '/' ) ? "" : "/" );
+ uri_encode( filename, buf + len, sizeof ( buf ) - len, URI_PATH);
uri = parse_uri ( buf );
if ( ! uri )
return NULL;
--
1.7.9.5
More information about the ipxe-devel
mailing list