From: Karel Zak Date: Tue, 6 Oct 2009 23:34:36 +0000 (+0200) Subject: namei: fix alone symlink evaluation X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1dca71078a9ed8eef35ba2b790d1e7db9421f66;p=util-linux namei: fix alone symlink evaluation $ 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 --- diff --git a/misc-utils/namei.c b/misc-utils/namei.c index b8930cdf..ebd82fdb 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -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) = '/';