]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: lxc_deslashify() handle special cases
authorChristian Brauner <christian.brauner@canonical.com>
Sun, 25 Sep 2016 21:57:13 +0000 (23:57 +0200)
committerChristian Brauner <christian.brauner@canonical.com>
Mon, 26 Sep 2016 17:41:34 +0000 (19:41 +0200)
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/criu.c
src/lxc/utils.c
src/lxc/utils.h

index 67d6fdc5519b82102b85e81b9d108c546edddc66..f228736437c540312eb3fa4864c091a12f1cde8e 100644 (file)
@@ -282,7 +282,7 @@ static void exec_criu(struct criu_opts *opts)
                        }
                }
 
-               if (!lxc_deslashify(path)) {
+               if (!lxc_deslashify(&path)) {
                        ERROR("failed to deslashify %s", path);
                        free(path);
                        goto err;
index c72c26a50896bfddcdf755e8589d90b8159883da..ebf3ad981d501bd06e8932932ea7ba709a6b1f30 100644 (file)
@@ -716,21 +716,40 @@ char **lxc_normalize_path(const char *path)
        return components;
 }
 
-bool lxc_deslashify(char *path)
+bool lxc_deslashify(char **path)
 {
-       char **parts = NULL, *path2;
+       char *p;
+       char **parts = NULL;
+       size_t n, len;
 
-       parts = lxc_normalize_path(path);
+       parts = lxc_normalize_path(*path);
        if (!parts)
                return false;
 
-       path2 = lxc_string_join("/", (const char **) parts, *path == '/');
-       lxc_free_array((void **) parts, free);
-       if (!path2)
+       /* We'll end up here if path == "///" or path == "". */
+       if (!*parts) {
+               len = strlen(*path);
+               if (!len)
+                       return true;
+               n = strcspn(*path, "/");
+               if (n == len) {
+                       p = strdup("/");
+                       if (!p)
+                               return false;
+                       free(*path);
+                       *path = p;
+                       return true;
+               }
+       }
+
+       p = lxc_string_join("/", (const char **)parts, **path == '/');
+       lxc_free_array((void **)parts, free);
+       if (!p)
                return false;
 
-       strncpy(path, path2, strlen(path));
-       free(path2);
+       free(*path);
+       *path = p;
+
        return true;
 }
 
index c2eef507b53f7be51a24b32d2d991822ee4694e8..88719a0f35508d0a2e257383c2db85fbaa250395 100644 (file)
@@ -249,7 +249,7 @@ extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_pr
  */
 extern char **lxc_normalize_path(const char *path);
 /* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
-extern bool lxc_deslashify(char *path);
+extern bool lxc_deslashify(char **path);
 extern char *lxc_append_paths(const char *first, const char *second);
 /* Note: the following two functions use strtok(), so they will never
  *       consider an empty element, even if two delimiters are next to