[lxc-devel] [PATCH 1/1] mkdir_p: account for '//foo/bar'
Serge Hallyn
serge.hallyn at ubuntu.com
Tue Apr 16 12:40:22 UTC 2013
Thanks, Richard. Does the following patch help?
(Disregard the spacing in original function, pushing a fix for that
separately)
As Richard reported, dirname('//') returns //. But mkdir_p only stops
when called with '/', resulting in infinite recursion when given a
pathname '//foo/bar'.
Reported-by: richard -rw- weinberger <richard.weinberger at gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/utils.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index ecf9d2c..b17f51d 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -95,12 +95,21 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
return 0;
}
+static int is_all_slashes(char *path)
+{
+ while (*path && *path == '/')
+ path++;
+ if (*path)
+ return 0;
+ return 1;
+}
+
extern int mkdir_p(char *dir, mode_t mode)
{
int ret;
char *d;
- if (!strcmp(dir, "/"))
+ if (is_all_slashes(dir))
return 0;
d = strdup(dir);
--
1.8.1.2
More information about the lxc-devel
mailing list