diff options
author | Joshua Oreman <oremanj@rwcr.net> | 2009-12-29 22:36:04 -0500 |
---|---|---|
committer | Marty Connor <mdc@etherboot.org> | 2010-01-20 18:14:28 -0500 |
commit | 3d9dd93a1452e28c728483b03e352691238491ed (patch) | |
tree | 73a41396fd514d12dbd7bd69ebfc49810bf73c7c /src/usr/autoboot.c | |
parent | ef9d1a32c6dc83d1086141c18d2be19a05ab8e49 (diff) | |
download | ipxe-3d9dd93a1452e28c728483b03e352691238491ed.tar.gz |
[uri] Decode/encode URIs when parsing/unparsing
Currently, handling of URI escapes is ad-hoc; escaped strings are
stored as-is in the URI structure, and it is up to the individual
protocol to unescape as necessary. This is error-prone and expensive
in terms of code size. Modify this behavior by unescaping in
parse_uri() and escaping in unparse_uri() those fields that typically
handle URI escapes (hostname, user, password, path, query, fragment),
and allowing unparse_uri() to accept a subset of fields to print so
it can be easily used to generate e.g. the escaped HTTP path?query
request.
Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
Signed-off-by: Marty Connor <mdc@etherboot.org>
Diffstat (limited to 'src/usr/autoboot.c')
-rw-r--r-- | src/usr/autoboot.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 8c4398c3f..2fa10e6bc 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -61,7 +61,9 @@ int boot_next_server_and_filename ( struct in_addr next_server, const char *filename ) { struct uri *uri; struct image *image; - char buf[ 23 /* tftp://xxx.xxx.xxx.xxx/ */ + strlen(filename) + 1 ]; + char buf[ 23 /* tftp://xxx.xxx.xxx.xxx/ */ + + ( 3 * strlen(filename) ) /* completely URI-encoded */ + + 1 /* NUL */ ]; int filename_is_absolute; int rc; @@ -78,8 +80,10 @@ int boot_next_server_and_filename ( struct in_addr next_server, * between filenames with and without initial slashes, * which is significant for TFTP. */ - snprintf ( buf, sizeof ( buf ), "tftp://%s/%s", - inet_ntoa ( next_server ), filename ); + snprintf ( buf, sizeof ( buf ), "tftp://%s/", + inet_ntoa ( next_server ) ); + uri_encode ( filename, buf + strlen ( buf ), + sizeof ( buf ) - strlen ( buf ), URI_PATH ); filename = buf; } |