]> err.no Git - util-linux/commitdiff
namei: fix alone symlink evaluation
authorKarel Zak <kzak@redhat.com>
Tue, 6 Oct 2009 23:34:36 +0000 (01:34 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 6 Oct 2009 23:34:36 +0000 (01:34 +0200)
$ mkdir aaa
$ ln -s aaa mylink

old version:

$ namei mylink
namei: could not stat 'mylink/aaa': No such file or directory

new version:

        $ namei mylink
f: mylink
 l mylink -> aaa
   d aaa

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/namei.c

index b8930cdf067aeee442a12e078e75848f76b1be89..ebd82fdb8a944018782c5e63910ab6800ae1b637 100644 (file)
@@ -190,14 +190,15 @@ readlink_to_namei(struct namei *nm, const char *path)
        if (*sym != '/') {
                char *p = strrchr(path, '/');
 
-               nm->relstart = p ? p - path : strlen(path);
-               sz += nm->relstart + 1;
+               nm->relstart = p ? p - path : 0;
+               if (nm->relstart)
+                       sz += nm->relstart + 1;
        }
        nm->abslink = malloc(sz + 1);
        if (!nm->abslink)
                err(EXIT_FAILURE, _("out of memory?"));
 
-       if (*sym != '/') {
+       if (*sym != '/' && nm->relstart) {
                /* create the absolute path from the relative symlink */
                memcpy(nm->abslink, path, nm->relstart);
                *(nm->abslink + nm->relstart) = '/';