[libvirt] [libvirt[]PATCH v2] 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", ] Issue "virsh -c hailly" results in matching "hail=qemu:///system" Fix URI alias prefix matching when connecting Signed-off-by: Wen Ruo Lv <lvroyce@linux.vnet.ibm.com> --- src/libvirt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index e9d1a29..54e283f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1022,7 +1022,7 @@ virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char * return -1; } - if (STREQLEN(entry->str, alias, offset-entry->str)) { + if (STREQLEN(entry->str, alias, strlen(alias))) { VIR_DEBUG("Resolved alias '%s' to '%s'", alias, offset+1); if (!(*uri = strdup(offset+1))) { -- 1.7.4.1

Hello Wen, On Tuesday 01 November 2011 04:08:24 Wen Ruo Lv wrote:
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", ] Issue "virsh -c hailly" results in matching "hail=qemu:///system" ... - if (STREQLEN(entry->str, alias, offset-entry->str)) { + if (STREQLEN(entry->str, alias, strlen(alias))) {
Now you have it the other way around, that any prefix matches: "virsh -c hai" will match "hail". Why not simply use STREQ instead of STREQLEN? Sincerely Philipp -- Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH Linux for Your Business fon: +49 421 22 232- 0 Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99 http://www.univention.de/

On 2011?11?01? 15:12, Philipp Hahn wrote:
Now you have it the other way around, that any prefix matches: "virsh -c hai" will match "hail". Why not simply use STREQ instead of STREQLEN?
Sincerely Philipp ooooooops..You're right.But here I think we can't use STREQ because in config file the compared string is "hail=qemu:///system"not just "hail" with NULL followed
is this one right? size_t alias_len; alias_len = strlen(alias); if (STREQLEN(entry->str, alias, alias_len) && alias_len == (offset-entry->str))
participants (3)
-
lvroyce
-
Philipp Hahn
-
Wen Ruo Lv