[libvirt] [PATCH] Fixed URI parsing

Eric Blake eblake at redhat.com
Fri Feb 24 23:49:40 UTC 2012


On 02/24/2012 11:48 AM, Martin Kletzander wrote:
> Function xmlParseURI does not remove square brackets around IPv6
> address when parsing. One of the solutions is making wrappers around
> functions working with xmlURI*. This assures that uri->server will be
> always properly assigned and it doesn't have to be changed when used
> on some new place in the code.
> For this purpose, functions virParseURI and virSaveURI were
> added. These function are wrappers around xmlParseURI and xmlSaveUri
> respectively.
> Also there is one new syntax check function to prohibit these functions
> anywhere else.
> 
> File changes:
>  - src/util/viruri.h        -- declaration
>  - src/util/viruri.c        -- definition
>  - src/libvirt_private.syms -- symbol export
>  - src/Makefile.am          -- added source and header files
>  - cfg.mk                   -- added sc_prohibit_xmlURI
>  - all others               -- ID name and include fixes

> +++ b/cfg.mk
> @@ -457,6 +457,12 @@ sc_prohibit_xmlGetProp:
>  	halt='use virXMLPropString, not xmlGetProp'			\
>  	  $(_sc_search_regexp)
> 
> +# xml(ParseURI|SaveUri) doesn't handle IPv6 URIs well
> +sc_prohibit_xmlURI:
> +	@prohibit='\<xml(ParseURI|SaveUri) *\('				\
> +	halt='use virURI(Parse|Format), not xml(ParseURI|SaveUri)'	\
> +	  $(_sc_search_regexp)
> +
>  # ATTRIBUTE_UNUSED should only be applied in implementations, not
>  # header declarations
>  sc_avoid_attribute_unused_in_header:
> @@ -758,6 +764,8 @@ exclude_file_name_regexp--sc_prohibit_strncpy = \
> 
>  exclude_file_name_regexp--sc_prohibit_xmlGetProp = ^src/util/xml\.c$$
> 
> +exclude_file_name_regexp--sc_prohibit_xmlURI = ^src/util/viruri\.c$$
> +

ACK; and pushed with these further changes squashed in to address Dan's
comments on v3.

diff --git i/src/util/viruri.c w/src/util/viruri.c
index 0cbfc5a..6c4dfe3 100644
--- i/src/util/viruri.c
+++ w/src/util/viruri.c
@@ -25,10 +25,10 @@
  *
  * @returns the parsed uri object with some fixes
  */
-xmlURIPtr
+virURIPtr
 virURIParse(const char *uri)
 {
-    xmlURIPtr ret = xmlParseURI(uri);
+    virURIPtr ret = xmlParseURI(uri);

     /* First check: does it even make sense to jump inside */
     if (ret != NULL &&
@@ -62,12 +62,12 @@ virURIParse(const char *uri)
  *
  * @returns the constructed uri as a string
  */
-unsigned char *
+char *
 virURIFormat(xmlURIPtr uri)
 {
     char *backupserver = NULL;
     char *tmpserver = NULL;
-    unsigned char *ret;
+    char *ret;

     /* First check: does it make sense to do anything */
     if (uri != NULL &&
@@ -81,7 +81,7 @@ virURIFormat(xmlURIPtr uri)
         uri->server = tmpserver;
     }

-    ret = xmlSaveUri(uri);
+    ret = (char *) xmlSaveUri(uri);

     /* Put the fixed version back */
     if (tmpserver) {
diff --git i/src/util/viruri.h w/src/util/viruri.h
index b2b0ca8..5215e42 100644
--- i/src/util/viruri.h
+++ w/src/util/viruri.h
@@ -16,7 +16,7 @@
 typedef xmlURI    virURI;
 typedef xmlURIPtr virURIPtr;

-virURIPtr        virURIParse(const char *uri);
-unsigned char *  virURIFormat(virURIPtr uri);
+virURIPtr virURIParse(const char *uri);
+char *virURIFormat(virURIPtr uri);

 #endif /* __VIR_URI_H__ */
diff --git i/src/libvirt.c w/src/libvirt.c
index a4ee63d..cbb4119 100644
--- i/src/libvirt.c
+++ w/src/libvirt.c
@@ -1729,7 +1729,7 @@ virConnectGetURI (virConnectPtr conn)
         return NULL;
     }

-    name = (char *)virURIFormat(conn->uri);
+    name = virURIFormat(conn->uri);
     if (!name) {
         virReportOOMError();
         goto error;
diff --git i/src/remote/remote_driver.c w/src/remote/remote_driver.c
index 8fb46e1..bcd78ee 100644
--- i/src/remote/remote_driver.c
+++ w/src/remote/remote_driver.c
@@ -504,7 +504,7 @@ doRemoteOpen (virConnectPtr conn,
                     transport_str[-1] = '\0';
                 }

-                name = (char *) virURIFormat (&tmpuri);
+                name = virURIFormat(&tmpuri);

 #ifdef HAVE_XMLURI_QUERY_RAW
                 VIR_FREE(tmpuri.query_raw);


-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120224/98b586c9/attachment-0001.sig>


More information about the libvir-list mailing list