The function removes multiple following slashes from paths. This is okay
unless you try to sanitize a URI this way. Skip the protocol definition
until "://" and sanitize just the path part.
The sanitization function is used in virStorageVolLookupByPath as the
first step before passing the path to storage drivers. This breaks
lookup of gluster volumes.
---
src/util/virfile.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 96f078d..6a09609 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2587,6 +2587,8 @@ virFileSanitizePath(const char *path)
const char *cur = path;
char *cleanpath;
int idx = 0;
+ const char *firstslash;
+ const char *uriseparator;
if (VIR_STRDUP(cleanpath, path) < 0)
return NULL;
@@ -2596,12 +2598,22 @@ virFileSanitizePath(const char *path)
* /// -> /
* /../foo -> /../foo
* /foo///bar/ -> /foo/bar
+ * Need to leave in place:
+ * :// - URIs
*/
+ /* find positions of first colon and first slash */
+ firstslash = strchr(path, '/');
+
/* Starting with // is valid posix, but ///foo == /foo */
if (cur[0] == '/' && cur[1] == '/' && cur[2] !=
'/') {
idx = 2;
cur += 2;
+ } else if ((uriseparator = strstr(path, "://")) &&
+ uriseparator < firstslash) {
+
+ cur = uriseparator + 3;
+ idx = cur - path;
}
/* Sanitize path in place */
--
1.8.5.5