From: Rob Landley Date: Mon, 24 Mar 2014 11:26:49 +0000 (-0500) Subject: Fix mkdir -p with absolute paths. X-Git-Tag: 0.5.0~291 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02f5a30ec0acf6c42441e5b06fb3ab41f629952a;p=platform%2Fupstream%2Ftoybox.git Fix mkdir -p with absolute paths. Stripping leading / is not the right thing to do there. Broken when the code moved to lib and was genericized for use elsewhere. --- diff --git a/lib/lib.c b/lib/lib.c index 1efb642..c1029d2 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -135,15 +135,12 @@ int mkpathat(int atfd, char *dir, mode_t lastmode, int flags) return 1; } - // Skip leading / of absolute paths - while (*dir == '/') dir++; - - for (s=dir; ;s++) { + for (s = dir; ;s++) { char save = 0; mode_t mode = (0777&~toys.old_umask)|0300; - // Skip leading / of absolute paths. - if (*s == '/' && (flags&2)) { + // find next '/', but don't try to mkdir "" at start of absolute path + if (*s == '/' && (flags&2) && s != dir) { save = *s; *s = 0; } else if (*s) continue;