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
---
v3:
- wrappers moved to new files
- syntax check added
- virAsprintf used instead of nasty memory mechanics
v2:
- added virSaveURI for building back the original string
cfg.mk |8
src/Makefile.am|3 +-
src/datatypes.h|2 +-
src/driver.h |2 +-
src/esx/esx_driver.c |5 +-
src/esx/esx_util.c |2 +-
src/esx/esx_util.h |4 +-
src/hyperv/hyperv_util.c |2 +-
src/hyperv/hyperv_util.h |5 +-
src/libvirt.c | 10 ++--
src/libvirt_private.syms |5 ++
src/libxl/libxl_driver.c |3 +-
src/lxc/lxc_driver.c |3 +-
src/openvz/openvz_driver.c |3 +-
src/qemu/qemu_driver.c |2 +-
src/qemu/qemu_migration.c |7 ++-
src/remote/remote_driver.c |9 ++--
src/uml/uml_driver.c |3 +-
src/util/qparams.c |3 +-
src/util/viruri.c | 91
src/util/viruri.h | 18 +
src/vbox/vbox_tmpl.c |3 +-
src/vmx/vmx.c |6 +-
src/xen/xen_driver.c |4 +-
src/xen/xen_hypervisor.h |3 +-
src/xen/xend_internal.c|4 +-
src/xen/xend_internal.h|2 +-
src/xenapi/xenapi_driver.c |2 +-
src/xenapi/xenapi_utils.c |4 +-
src/xenapi/xenapi_utils.h |4 +-
30 files changed, 174 insertions(+), 48 deletions(-)
create mode 100644 src/util/viruri.c
create mode 100644 src/util/viruri.h
diff --git a/cfg.mk b/cfg.mk
index dcf44bb..9759d87 100644
--- a/cfg.mk
+++ 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='\
-# include
# include "internal.h"
+# include "viruri.h"
/*
* List of registered drivers numbers
*/
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index f5e1cc7..b6b22f8 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -44,6 +44,7 @@
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "viruri.h"
#define VIR_FROM_THIS VIR_FROM_ESX
@@ -3945,7 +3946,7 @@ esxDomainMigratePerform(virDomainPtr domain,
{
int result = -1;
esxPrivate *priv = domain->conn->privateData;
-xmlURIPtr parsedUri = NULL;
+virURIPtr parsedUri = NULL;
char *saveptr;
char *path_resourcePool;
char *path_hostSystem;
@@ -3976,7 +3977,7 @@ esxDomainMigratePerform(virDomainPtr domain,
}
/* Parse migration URI */
-parsedUri = xmlParseURI(uri);
+parsedUri = virURIParse(uri);
if (parsedUri == NULL) {
virReportOOMError();
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 2c5ac1a..7d4b908 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -42,7 +42,7 @@
int
-esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, xmlURIPtr uri)
+esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
{
int result = -1;
struct qparam_set *queryParamSet = NULL;
diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h
index 2bee510..a69b3f4 100644
--- a/src/esx/esx_util.h
+++ b/src/esx/esx_util.h
@@ -22,9 +22,9 @@
#ifndef __ESX_UTIL_H__
# define __ESX_UTIL_H__
-# include
# include
# include "internal.h"
+# include "viruri.h"
typedef struct _esxUtil_ParsedUri esxUtil_ParsedUri;
@@ -40,7 +40,7 @@ struct _esxUtil_ParsedUri {
char *path;
};
-int esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, xmlURIPtr uri);
+int esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri);
void esxUtil_FreeParsedUri(esxUtil_ParsedUri **parsedUri);
diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c
index 298cfe0..2e6a2d4 100644
--- a/src/hyperv/hyperv_util.c
+++ b/src/hyperv/hyperv_util.c
@@ -37,7 +37,7 @@
int
-hypervParseUri(hypervParsedUri **parsedUri, xmlURIPtr uri)
+hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
{
int result = -1;
struct qparam_set *queryParamSet = NULL;
diff --git a/src/hyperv/hyperv_util.h b/src/hyperv/hyperv_ut