]> err.no Git - util-linux/commitdiff
namei: don't duplicate '/' directory
authorKarel Zak <kzak@redhat.com>
Mon, 26 Jan 2009 10:36:31 +0000 (11:36 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 26 Jan 2009 10:36:31 +0000 (11:36 +0100)
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 <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/namei.c

index c259b30f7d0437245ffcb4b683cae60a9c1dd9ff..e2d4f7e65eec8383d76dc55786e0a739abfc8d74 100644 (file)
@@ -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))