[uri] Refactor URI parsing and formatting
Add support for parsing of URIs containing literal IPv6 addresses (e.g. "http://[fe80::69ff:fe50:5845%25net0]/boot.ipxe"). Duplicate URIs by directly copying the relevant fields, rather than by formatting and reparsing a URI string. This relaxes the requirements on the URI formatting code and allows it to focus on generating human-readable URIs (e.g. by not escaping ':' characters within literal IPv6 addresses). As a side-effect, this allows relative URIs containing parameter lists (e.g. "../boot.php##params") to function as expected. Add validity check for FTP paths to ensure that only printable characters are accepted (since FTP is a human-readable line-based protocol with no support for character escaping). Construct TFTP next-server+filename URIs directly, rather than parsing a constructed "tftp://..." string, Add self-tests for URI functions. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
+29
-2
@@ -23,6 +23,7 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/socket.h>
|
||||
#include <ipxe/tcpip.h>
|
||||
@@ -459,6 +460,25 @@ static struct interface_descriptor ftp_xfer_desc =
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check validity of FTP control channel string
|
||||
*
|
||||
* @v string String
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ftp_check_string ( const char *string ) {
|
||||
char c;
|
||||
|
||||
/* The FTP control channel is line-based. Check for invalid
|
||||
* non-printable characters (e.g. newlines).
|
||||
*/
|
||||
while ( ( c = *(string++) ) ) {
|
||||
if ( ! isprint ( c ) )
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate an FTP connection
|
||||
*
|
||||
@@ -472,10 +492,17 @@ static int ftp_open ( struct interface *xfer, struct uri *uri ) {
|
||||
int rc;
|
||||
|
||||
/* Sanity checks */
|
||||
if ( ! uri->path )
|
||||
return -EINVAL;
|
||||
if ( ! uri->host )
|
||||
return -EINVAL;
|
||||
if ( ! uri->path )
|
||||
return -EINVAL;
|
||||
if ( ( rc = ftp_check_string ( uri->path ) ) != 0 )
|
||||
return rc;
|
||||
if ( uri->user && ( ( rc = ftp_check_string ( uri->user ) ) != 0 ) )
|
||||
return rc;
|
||||
if ( uri->password &&
|
||||
( ( rc = ftp_check_string ( uri->password ) ) != 0 ) )
|
||||
return rc;
|
||||
|
||||
/* Allocate and populate structure */
|
||||
ftp = zalloc ( sizeof ( *ftp ) );
|
||||
|
||||
Reference in New Issue
Block a user