zsh-workers
 help / color / mirror / code / Atom feed
* broken readlink() call in glob.c
@ 2005-08-14 21:49 Wayne Davison
  0 siblings, 0 replies; only message in thread
From: Wayne Davison @ 2005-08-14 21:49 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

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..

[-- Attachment #2: glob.patch --]
[-- Type: text/plain, Size: 426 bytes --]

--- 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);
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-08-14 21:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-14 21:49 broken readlink() call in glob.c Wayne Davison

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).