zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: zsh 5.0.5-dev-2
Date: Thu, 14 Aug 2014 21:44:12 -0700	[thread overview]
Message-ID: <140814214412.ZM4177@torch.brasslantern.com> (raw)
In-Reply-To: <20140814205429.44baf512@pws-pc.ntlworld.com>

On Aug 14,  8:54pm, Peter Stephenson wrote:
}
} It's entirely unclear to me from looking at xsymlinks() when an empty
} xbuf would actually constitute a failure.

This occurs in the (t0 == -1) case when the reason that readlink() has
failed is because the path so far concatenated with the next segment of
the split path has produced a string longer than PATH_MAX.  In that case
(xbuflen + pplen > sizeof(xbuf)) we completely truncate xbuf and give up.

} If it can't expand something
} as a symbolic link it simply treats it literally;

Yes, but for a /path/to/somereallylongname, appending somereallylongname
to the expansion of xbuf so far, might overflow xbuf.

} If we don't have an answer now I'd be inclined to comment out the
} warning.

Maybe just make xsymlinks() have a ternary return value instead of a
boolean one, and return an actual error value in the case where we've
truncated on overflow instead of as part of normal expansion to root?

I don't know if all of these changes are necessary.  It has always
bothered me that the return value of the recursive calls to xsymlinks()
are ignored, but maybe this isn't the right way to handle them.

Incidentally, anybody recall what the obviously obsolete comment above
the xsymlinks() definition in Src/utils.c is about?

diff --git a/Src/utils.c b/Src/utils.c
index 998e46a..076a33c 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -716,7 +716,6 @@ slashsplit(char *s)
 }
 
 /* expands symlinks and .. or . expressions */
-/* if flag = 0, only expand .. and . expressions */
 
 /**/
 static int
@@ -753,6 +752,7 @@ xsymlinks(char *s)
 		strcat(xbuf, *pp);
 	    } else {
 		*xbuf = 0;
+		ret = -1;
 		break;
 	    }
 	} else {
@@ -760,9 +760,11 @@ xsymlinks(char *s)
 	    metafy(xbuf3, t0, META_NOALLOC);
 	    if (*xbuf3 == '/') {
 		strcpy(xbuf, "");
-		xsymlinks(xbuf3 + 1);
+		if (xsymlinks(xbuf3 + 1) < 0)
+		    ret = -1;
 	    } else
-		xsymlinks(xbuf3);
+		if (xsymlinks(xbuf3) < 0)
+		    ret = -1;
 	}
     }
     freearray(opp);
@@ -781,11 +783,10 @@ xsymlink(char *s)
     if (*s != '/')
 	return NULL;
     *xbuf = '\0';
-    xsymlinks(s + 1);
-    if (!*xbuf) {
+    if (xsymlinks(s + 1) < 0)
 	zwarn("path expansion failed, using root directory");
+    if (!*xbuf)
 	return ztrdup("/");
-    }
     return ztrdup(xbuf);
 }
 
@@ -795,7 +796,7 @@ print_if_link(char *s)
 {
     if (*s == '/') {
 	*xbuf = '\0';
-	if (xsymlinks(s + 1))
+	if (xsymlinks(s + 1) > 0)
 	    printf(" -> "), zputs(*xbuf ? xbuf : "/", stdout);
     }
 }

-- 
Barton E. Schaefer


  reply	other threads:[~2014-08-15  4:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12 20:29 Peter Stephenson
2014-08-12 22:36 ` Axel Beckert
2014-08-13 14:04   ` zsh 5.0.5-dev-2 / Occassional hangs on Test/A05execution.ztst Axel Beckert
2014-08-13 19:08     ` Bart Schaefer
2014-08-14  8:48       ` Axel Beckert
2014-08-14  8:50       ` Peter Stephenson
2014-08-14 16:25         ` Bart Schaefer
2014-08-14 16:31           ` Axel Beckert
2014-08-14 17:34             ` Axel Beckert
2014-08-15  4:50               ` Bart Schaefer
2014-08-15  9:32                 ` Axel Beckert
2014-08-15 17:33                   ` Bart Schaefer
2014-08-15 19:42                     ` Axel Beckert
2014-08-16 18:12                       ` zsh 5.0.5/6 Peter Stephenson
2014-08-13 17:28   ` zsh 5.0.5-dev-2 Dominic Hopf
2014-08-13 22:34 ` Oliver Kiddle
2014-08-14  8:34   ` Peter Stephenson
2014-08-14  9:32     ` Peter Stephenson
2014-08-14 16:20       ` Bart Schaefer
2014-08-14 19:54         ` Peter Stephenson
2014-08-15  4:44           ` Bart Schaefer [this message]
2014-08-15  8:38             ` Peter Stephenson
2014-08-15 11:23             ` Han Pingtian
2014-08-15 17:17               ` Bart Schaefer
2014-08-16  0:35                 ` Han Pingtian
2014-08-17 17:30                   ` Bart Schaefer
2014-08-18  2:56                     ` Han Pingtian
2014-08-18  6:36                       ` Bart Schaefer
2014-08-18 14:02                         ` Han Pingtian
2014-08-23 17:51                     ` Symlink chasing Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140814214412.ZM4177@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).