Subject: Re: lib/30943: realpath() behaviour changed with nonexistant relative path
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Mark Davies <mark@mcs.vuw.ac.nz>
List: netbsd-bugs
Date: 08/13/2005 02:45:02
The following reply was made to PR lib/30943; it has been noted by GNATS.

From: Mark Davies <mark@mcs.vuw.ac.nz>
To: Elad Efrat <elad@netbsd.org>
Cc: gnats-bugs@netbsd.org
Subject: Re: lib/30943: realpath() behaviour changed with nonexistant relative path
Date: Sat, 13 Aug 2005 14:43:54 +1200

 On Saturday 13 August 2005 12:04, Elad Efrat wrote:
 
 >    [ look how removing the trailing slash makes revision 1.36 behave
 >       ``wrong''. revision 1.38 didn't introduce bad behavior - it
 >       fixed a bug in revision 1.36.]
 
 I realise that 1.38 "fixed" a bug to give consistent behavior whether or not 
 you had a trailing slash its just that, the more I look at 
 http://www.opengroup.org/onlinepubs/009695399/functions/realpath.html
 and at implementations on other systems, I think that that behavior - of 
 allowing the last element not to exist (with or without trailing slash) is 
 wrong.  So I thing the correct patch is very similar to your "revision 1.39"
 
 Index: getcwd.c
 ===================================================================
 RCS file: /src/cvs/netbsd/src/lib/libc/gen/getcwd.c,v
 retrieving revision 1.38
 diff -u -r1.38 getcwd.c
 --- getcwd.c	5 Jul 2005 02:56:12 -0000	1.38
 +++ getcwd.c	13 Aug 2005 02:40:55 -0000
 @@ -159,13 +159,6 @@
  	 * target to unresolved path.
  	 */
  	if (lstat(resolved, &sb) == -1) {
 -		/* Allow nonexistent component if this is the last one. */
 -		while (*q == '/')
 -			q++;
 -		if (*q == 0 && errno == ENOENT) {
 -			errno = serrno;
 -			return (resolved);
 -		}
  		return (NULL);
  	}
  	if (S_ISLNK(sb.st_mode)) {
 Index: realpath.3
 ===================================================================
 RCS file: /src/cvs/netbsd/src/lib/libc/gen/realpath.3,v
 retrieving revision 1.11
 diff -u -r1.11 realpath.3
 --- realpath.3	7 Aug 2003 16:42:55 -0000	1.11
 +++ realpath.3	13 Aug 2005 02:41:36 -0000
 @@ -72,11 +72,6 @@
  function will resolve both absolute and relative paths
  and return the absolute pathname corresponding to
  .Fa pathname .
 -All but the last component of
 -.Fa pathname
 -must exist when
 -.Fn realpath
 -is called.
  .Sh RETURN VALUES
  The
  .Fn realpath
 
 
 cheers
 mark