[gPXE-devel] [PATCH 05/31] [uri] fixed URI passing to handle IPv6 addresses in URIs

matthew at theiselins.net matthew at theiselins.net
Fri Jul 8 10:28:14 EDT 2011


From: Matthew Iselin <matthew at theiselins.net>

Signed-off-by: Matthew Iselin <matthew at theiselins.net>
---
 src/core/uri.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/core/uri.c b/src/core/uri.c
index 1a43206..1cbf1f1 100644
--- a/src/core/uri.c
+++ b/src/core/uri.c
@@ -167,9 +167,20 @@ struct uri * parse_uri ( const char *uri_string ) {
 
 		/* Split host into host[:port] */
 		if ( ( tmp = strchr ( uri->host, ':' ) ) ) {
-			*(tmp++) = '\0';
-			uri->port = tmp;
+			/* Make sure an IPv6 address isn't broken up. */
+			if ( ( strchr ( uri->host, '[' ) == 0 ) ||
+			     ( tmp > strchr ( uri->host, ']' ) ) ) {
+				*(tmp++) = '\0';
+				uri->port = tmp;
+			}
 		}
+		
+		/* Handle IPv6 case. */
+		if ( ( uri->host <= strchr ( uri->host, '[' ) ) &&
+		     ( tmp = strchr ( uri->host, ']' ) ) ) {
+			uri->host++;
+			*(tmp) = 0;
+	        }
 	}
 
 	/* Decode fields that should be decoded */
@@ -411,6 +422,10 @@ static int is_unreserved_uri_char ( int c, int field ) {
 		    ( c == '-' ) || ( c == '_' ) ||
 		    ( c == '.' ) || ( c == '~' ) );
 
+	/* : is valid for an IPv6 host address */
+	if ( field == URI_HOST )
+		ok = ok || (c == ':');
+
 	if ( field == URI_QUERY )
 		ok = ok || ( c == ';' ) || ( c == '&' ) || ( c == '=' );
 
-- 
1.7.2.5



More information about the gPXE-devel mailing list