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 <lvroyce@linux.vnet.ibm.com>
This commit is contained in:
Wen Ruo Lv 2011-11-01 17:49:06 +08:00 committed by Eric Blake
parent 20e4e9872d
commit 8bec4ff2f1
2 changed files with 6 additions and 1 deletions

View File

@ -201,6 +201,7 @@ Patches have also been contributed by:
David L Stevens <dlstevens@us.ibm.com>
Tyler Coumbes <coumbes@gmail.com>
Josh Durgin <josh.durgin@dreamhost.com>
Wen Ruo Lv <lvroyce@linux.vnet.ibm.com>
[....send patches to get your name here....]

View File

@ -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))) {