From 8bec4ff2f15daef0b3b0034240319dd4376d1ea2 Mon Sep 17 00:00:00 2001 From: Wen Ruo Lv Date: Tue, 1 Nov 2011 17:49:06 +0800 Subject: [PATCH] Fix URI alias prefix matching with /etc/libvirt/libvirt.conf below: uri_aliases = [ "hail=qemu:///system", "sleet=qemu+ssh://root 9 115 122 57/system", "sam=qemu+unix:///system?socket=/var/run/libvirt/libvirt-sock", ] Neither "virsh -c hailly" nor "hai" should result in matching "hail=qemu:///system" Fix URI alias prefix matching when connecting Signed-off-by: Wen Ruo Lv --- AUTHORS | 1 + src/libvirt.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 1040117c09..5bd49b332f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -201,6 +201,7 @@ Patches have also been contributed by: David L Stevens Tyler Coumbes Josh Durgin + Wen Ruo Lv [....send patches to get your name here....] diff --git a/src/libvirt.c b/src/libvirt.c index e9d1a299f2..f7ff98d36a 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -990,6 +990,8 @@ static int virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char **uri) { virConfValuePtr entry; + size_t alias_len; + if (value->type != VIR_CONF_LIST) { virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s", _("Expected a list for 'uri_aliases' config parameter")); @@ -997,6 +999,7 @@ virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char * } entry = value->list; + alias_len = strlen(alias); while (entry) { char *offset; size_t safe; @@ -1022,7 +1025,8 @@ virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char * return -1; } - if (STREQLEN(entry->str, alias, offset-entry->str)) { + if (alias_len == (offset - entry->str) && + STREQLEN(entry->str, alias, alias_len)) { VIR_DEBUG("Resolved alias '%s' to '%s'", alias, offset+1); if (!(*uri = strdup(offset+1))) {