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

broken readlink() call in glob.c



Gcc 4 complained about a readlink() call in glob.c that had a NULL
buffer arg, so I checked the code, and it appears that the function
statfullpath() always returned 1 (missing file) for a symlink that
points nowhere.  This is due to the readlink() call with a zero-sized
buffer always returning -1 (on my system, at least).  The fix is to
supply a one-character buffer so that readlink() only returns a -1
when the file is totally missing or cannot be read.  Patch appended.

..wayne..
--- Src/glob.c	2 Aug 2005 09:23:41 -0000	1.43
+++ Src/glob.c	14 Aug 2005 21:40:58 -0000
@@ -259,8 +259,10 @@ statfullpath(const char *s, struct stat 
 	l = 0;
     }
     unmetafy(buf, NULL);
-    if (!st)
-	return access(buf, F_OK) && (!l || readlink(buf, NULL, 0));
+    if (!st) {
+	char lbuf[1];
+	return access(buf, F_OK) && (!l || readlink(buf, lbuf, 1) < 0);
+    }
     return l ? lstat(buf, st) : stat(buf, st);
 }
 


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