From: Karel Zak Date: Mon, 26 Jan 2009 10:36:31 +0000 (+0100) Subject: namei: don't duplicate '/' directory X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=922a121b6065ae8fd124a72cd0b7e8b9b890f9f6;p=util-linux namei: don't duplicate '/' directory sake@lelux ~ namei -l / f: / drwxr-xr-x root root / drwxr-xr-x root root The duplicate '/' directory is unexpected behavior. Reported-by: Sami Kerola Signed-off-by: Karel Zak --- diff --git a/misc-utils/namei.c b/misc-utils/namei.c index c259b30f..e2d4f7e6 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -256,12 +256,15 @@ add_namei(struct namei *parent, const char *orgpath, int start, struct namei **l for (end = fname; fname && end; ) { /* set end of filename */ - end = strchr(fname, '/'); - if (end) - *end = '\0'; - - /* create a new entry */ - nm = new_namei(nm, path, fname, level); + if (*fname) { + end = strchr(fname, '/'); + if (end) + *end = '\0'; + + /* create a new entry */ + nm = new_namei(nm, path, fname, level); + } else + end = NULL; if (!first) first = nm; if (S_ISLNK(nm->st.st_mode))