[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3] 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>
---
 src/libvirt.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index e9d1a29..6f8a76f 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))) {
-- 
1.7.4.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]