Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: symlink chain.



On Sun, 4 Jan 2015 13:04:20 -0500
Vin Shelton <acs@xxxxxxxxxxxxxxxxxxxx> wrote:
> $ echo $PATH
> /home/acs/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin:/etc
> 
> $ ls -ld /opt /opt/xemacs /opt/bin/xemacs
> lrwxrwxrwx 1 root root 12 Nov 30 23:09 /opt -> raid-3tb/opt
> lrwxrwxrwx 1 acs  acs  20 Nov 19  2013 /opt/bin/xemacs -> ../xemacs/bin/xemacs
> lrwxrwxrwx 1 acs  acs  22 Jan  1 08:57 /opt/xemacs -> xemacs-21.4-2015-01-01
> 
> So /opt/bin/xemacs points to a particular xemacs installation
> 
> $ /opt/zsh-2015-01-01/bin/zsh -f
> legolas-i5% whence -s xemacs
> /opt/bin/xemacs -> /raid-3tb/opt/xemacs-21.4-2015-01-01/bin/xemacs-21.4.22

This interesting example of chains of symlinkx tickles an existing
problem with xsymlinks() (I think --- its behaviour is a bit obscure)
that causes whence -S to fail.  In resolving "..", xbuflen counts the
final '\0', which it doesn't elsewhere --- xbuflen at the end is
equivalent to strlen(xbuf) after the final '\0' has been appended.

This was obscured by the fact that we usually strcat() onto xbuf, so
making xbuflen less useful than it might be.  The code I added uses
strcpy(xbuf + xbuflen), hence showing the problem.  It would be
preferable to use strcpy() in both places but I'm fed up fixing bugs for
today.

diff --git a/Src/utils.c b/Src/utils.c
index 959df9a..390f513 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -741,6 +741,8 @@ xsymlinks(char *s, int full)
 	    while (*--p != '/')
 		xbuflen--;
 	    *p = '\0';
+	    /* The \0 isn't included in the length */
+	    xbuflen--;
 	    continue;
 	}
 	sprintf(xbuf2, "%s/%s", xbuf, *pp);

pws



Messages sorted by: Reverse Date, Date, Thread, Author