e942243
diff -rup libvirt-0.7.1/src/libvirt_private.syms paths/src/libvirt_private.syms
e942243
--- libvirt-0.7.1/src/libvirt_private.syms	2010-05-26 12:48:49.276277000 -0400
e942243
+++ paths/src/libvirt_private.syms	2010-05-26 13:00:47.501023000 -0400
e942243
@@ -417,6 +417,7 @@ virParseMacAddr;
e942243
 virFileDeletePid;
e942243
 virFindFileInPath;
e942243
 virFileExists;
e942243
+virFileSanitizePath;
e942243
 virFileHasSuffix;
e942243
 virFileLinkPointsTo;
e942243
 virFileMakePath;
e942243
diff -rup libvirt-0.7.1/src/storage_conf.c paths/src/storage_conf.c
e942243
--- libvirt-0.7.1/src/storage_conf.c	2010-05-26 12:48:48.885306000 -0400
e942243
+++ paths/src/storage_conf.c	2010-05-26 13:00:17.027330000 -0400
e942243
@@ -463,6 +463,7 @@ virStoragePoolDefParseXML(virConnectPtr 
e942243
     char *type = NULL;
e942243
     char *uuid = NULL;
e942243
     char *authType = NULL;
e942243
+    char *tmppath;
e942243
 
e942243
     if (VIR_ALLOC(ret) < 0) {
e942243
         virReportOOMError(conn);
e942243
@@ -610,11 +611,15 @@ virStoragePoolDefParseXML(virConnectPtr 
e942243
             goto cleanup;
e942243
     }
e942243
 
e942243
-    if ((ret->target.path = virXPathString(conn, "string(./target/path)", ctxt)) == NULL) {
e942243
+    if ((tmppath = virXPathString(conn, "string(./target/path)", ctxt)) == NULL) {
e942243
         virStorageReportError(conn, VIR_ERR_XML_ERROR,
e942243
                               "%s", _("missing storage pool target path"));
e942243
         goto cleanup;
e942243
     }
e942243
+    ret->target.path = virFileSanitizePath(tmppath);
e942243
+    VIR_FREE(tmppath);
e942243
+    if (!ret->target.path)
e942243
+        goto cleanup;
e942243
 
e942243
     if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
e942243
                                 "./target/permissions", 0700) < 0)
e942243
diff -rup libvirt-0.7.1/src/storage_driver.c paths/src/storage_driver.c
e942243
--- libvirt-0.7.1/src/storage_driver.c	2009-09-10 09:45:00.000000000 -0400
e942243
+++ paths/src/storage_driver.c	2010-05-26 12:59:14.815537000 -0400
e942243
@@ -1152,6 +1152,11 @@ storageVolumeLookupByPath(virConnectPtr 
e942243
     virStorageDriverStatePtr driver = conn->storagePrivateData;
e942243
     unsigned int i;
e942243
     virStorageVolPtr ret = NULL;
e942243
+    char *cleanpath;
e942243
+
e942243
+    cleanpath = virFileSanitizePath(path);
e942243
+    if (!cleanpath)
e942243
+        return NULL;
e942243
 
e942243
     storageDriverLock(driver);
e942243
     for (i = 0 ; i < driver->pools.count && !ret ; i++) {
e942243
@@ -1162,7 +1167,7 @@ storageVolumeLookupByPath(virConnectPtr 
e942243
 
e942243
             stable_path = virStorageBackendStablePath(conn,
e942243
                                                       driver->pools.objs[i],
e942243
-                                                      path);
e942243
+                                                      cleanpath);
e942243
             /*
e942243
              * virStorageBackendStablePath already does
e942243
              * virStorageReportError if it fails; we just need to keep
e942243
@@ -1191,6 +1196,7 @@ storageVolumeLookupByPath(virConnectPtr 
e942243
                               "%s", _("no storage vol with matching path"));
e942243
 
e942243
 cleanup:
e942243
+    VIR_FREE(cleanpath);
e942243
     storageDriverUnlock(driver);
e942243
     return ret;
e942243
 }
e942243
diff -rup libvirt-0.7.1/src/util.c paths/src/util.c
e942243
--- libvirt-0.7.1/src/util.c	2010-05-26 12:48:48.840341000 -0400
e942243
+++ paths/src/util.c	2010-05-26 12:58:02.088721000 -0400
e942243
@@ -1126,6 +1126,55 @@ int virFileExists(const char *path)
e942243
     return(0);
e942243
 }
e942243
 
e942243
+/* Remove spurious / characters from a path. The result must be freed */
e942243
+char *
e942243
+virFileSanitizePath(const char *path)
e942243
+{
e942243
+    const char *cur = path;
e942243
+    char *cleanpath;
e942243
+    int idx = 0;
e942243
+
e942243
+    cleanpath = strdup(path);
e942243
+    if (!cleanpath) {
e942243
+        virReportOOMError(NULL);
e942243
+        return NULL;
e942243
+    }
e942243
+
e942243
+    /* Need to sanitize:
e942243
+     * //           -> //
e942243
+     * ///          -> /
e942243
+     * /../foo      -> /../foo
e942243
+     * /foo///bar/  -> /foo/bar
e942243
+     */
e942243
+
e942243
+    /* Starting with // is valid posix, but ///foo == /foo */
e942243
+    if (cur[0] == '/' && cur[1] == '/' && cur[2] != '/') {
e942243
+        idx = 2;
e942243
+        cur += 2;
e942243
+    }
e942243
+
e942243
+    /* Sanitize path in place */
e942243
+    while (*cur != '\0') {
e942243
+        if (*cur != '/') {
e942243
+            cleanpath[idx++] = *cur++;
e942243
+            continue;
e942243
+        }
e942243
+
e942243
+        /* Skip all extra / */
e942243
+        while (*++cur == '/')
e942243
+            continue;
e942243
+
e942243
+        /* Don't add a trailing / */
e942243
+        if (idx != 0 && *cur == '\0')
e942243
+            break;
e942243
+
e942243
+        cleanpath[idx++] = '/';
e942243
+    }
e942243
+    cleanpath[idx] = '\0';
e942243
+
e942243
+    return cleanpath;
e942243
+}
e942243
+
e942243
 int virFileMakePath(const char *path)
e942243
 {
e942243
     struct stat st;
e942243
diff -rup libvirt-0.7.1/src/util.h paths/src/util.h
e942243
--- libvirt-0.7.1/src/util.h	2010-05-26 12:48:48.749342000 -0400
e942243
+++ paths/src/util.h	2010-05-26 12:56:57.494264000 -0400
e942243
@@ -107,6 +107,9 @@ char *virFindFileInPath(const char *file
e942243
 
e942243
 int virFileExists(const char *path);
e942243
 
e942243
+char *virFileSanitizePath(const char *path);
e942243
+
e942243
+
e942243
 int virFileMakePath(const char *path);
e942243
 
e942243
 int virFileBuildPath(const char *dir,