From nobody@FreeBSD.org  Mon Jul  4 16:21:36 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B856216A41C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  4 Jul 2005 16:21:36 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 8FD4A43D49
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  4 Jul 2005 16:21:36 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j64GLZlp018353
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 4 Jul 2005 16:21:35 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j64GLZJE018343;
	Mon, 4 Jul 2005 16:21:35 GMT
	(envelope-from nobody)
Message-Id: <200507041621.j64GLZJE018343@www.freebsd.org>
Date: Mon, 4 Jul 2005 16:21:35 GMT
From: Imri Zvik <imriz@co.zahav.net.il>
To: freebsd-gnats-submit@FreeBSD.org
Subject: realpath(3) treats regular files as directories
X-Send-Pr-Version: www-2.3

>Number:         82980
>Category:       kern
>Synopsis:       [libc] realpath(3) treats regular files as directories
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 04 16:30:17 GMT 2005
>Closed-Date:    
>Last-Modified:  Sun Apr 13 19:52:19 UTC 2014
>Originator:     Imri Zvik
>Release:        5.4-RELEASE-p2 or 4.11-RELEASE-p9
>Organization:
Internet Gold
>Environment:
FreeBSD irving.inter.net.il 5.4-RELEASE-p2 FreeBSD 5.4-RELEASE-p2 #0: Sun Jun 19 10:08:28 IDT 2005     root@irving.inter.net.il:/usr/obj/usr/src/sys/IGLD  amd64
>Description:
realpath resolves things like /tmp/test/. where /tmp/test is a regular file.
>How-To-Repeat:
touch /tmp/test
realpath /tmp/test/.
>Fix:
      
>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Imri Zvik <imriz@co.zahav.net.il>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: misc/82980: realpath(3) treats regular files as directories
Date: Tue, 5 Jul 2005 02:04:25 +0300

 On 2005-07-04 16:21, Imri Zvik <imriz@co.zahav.net.il> wrote:
 > realpath resolves things like /tmp/test/. where /tmp/test is a regular
 > file.
 >
 > touch /tmp/test
 > realpath /tmp/test/.
 
 This seems to work correctly in CURRENT and src/bin/realpath/realpath.c
 doesn't have any difference from RELENG_5 -> CURRENT.  Whatever is the
 cause, seems to be kernel-related
 

From: "Imri Zvik" <imriz@co.zahav.net.il>
To: <bug-followup@FreeBSD.org>
Cc:  
Subject: Re: kern/82980: realpath(3) treats regular files as directories
Date: Tue, 5 Jul 2005 10:31:06 +0300

 I thought it is libc related (?).
 
 Anyhow, the same problem was discovered in NetBSD too, and here is their
 patch:
 http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getcwd.c.diff?r1-1.36&r2-1.37&f-h
 
 
 --
 Imri Zvik
 PGP (2.6.3ia) Public Key: http://mariska.inter.net.il/~imriz/imriz.pgp
 

From: Garrett Cooper <yanegomi@gmail.com>
To: bug-followup@FreeBSD.org, imriz@co.zahav.net.il
Cc:  
Subject: Re: kern/82980: [libc] realpath(3) treats regular files as 
	directories
Date: Sun, 25 Apr 2010 01:14:42 -0700

     Here's a link to the diff committed via NetBSD:
 http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getcwd.c.diff?r1=1.36&r2=1.36.2.1
 , as the old link is broken.
 Cheers,
 -Garrett

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/82980: commit references a PR
Date: Sun, 13 Apr 2014 19:48:32 +0000 (UTC)

 Author: jilles
 Date: Sun Apr 13 19:48:28 2014
 New Revision: 264417
 URL: http://svnweb.freebsd.org/changeset/base/264417
 
 Log:
   realpath(): Properly fail "." or ".." components after non-directories.
   
   If realpath() is called on pathnames like "/dev/null/." or "/dev/null/..",
   it should fail with [ENOTDIR]. Pathnames like "/dev/null/" already failed as
   they should.
   
   Also, put the check for non-directories after lstatting the previous
   component instead of when the empty component (consecutive or trailing
   slashes) is detected, saving an lstat() call and some lines of code.
   
   PR:		kern/82980
   MFC after:	2 weeks
 
 Modified:
   head/lib/libc/stdlib/realpath.c
 
 Modified: head/lib/libc/stdlib/realpath.c
 ==============================================================================
 --- head/lib/libc/stdlib/realpath.c	Sun Apr 13 18:51:39 2014	(r264416)
 +++ head/lib/libc/stdlib/realpath.c	Sun Apr 13 19:48:28 2014	(r264417)
 @@ -132,26 +132,7 @@ realpath(const char * __restrict path, c
  			resolved[resolved_len] = '\0';
  		}
  		if (next_token[0] == '\0') {
 -			/*
 -			 * Handle consequential slashes.  The path
 -			 * before slash shall point to a directory.
 -			 *
 -			 * Only the trailing slashes are not covered
 -			 * by other checks in the loop, but we verify
 -			 * the prefix for any (rare) "//" or "/\0"
 -			 * occurrence to not implement lookahead.
 -			 */
 -			if (lstat(resolved, &sb) != 0) {
 -				if (m)
 -					free(resolved);
 -				return (NULL);
 -			}
 -			if (!S_ISDIR(sb.st_mode)) {
 -				if (m)
 -					free(resolved);
 -				errno = ENOTDIR;
 -				return (NULL);
 -			}
 +			/* Handle consequential slashes. */
  			continue;
  		}
  		else if (strcmp(next_token, ".") == 0)
 @@ -236,6 +217,11 @@ realpath(const char * __restrict path, c
  				}
  			}
  			left_len = strlcpy(left, symlink, sizeof(left));
 +		} else if (!S_ISDIR(sb.st_mode) && p != NULL) {
 +			if (m)
 +				free(resolved);
 +			errno = ENOTDIR;
 +			return (NULL);
  		}
  	}
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sun Apr 13 19:51:25 UTC 2014 
State-Changed-Why:  
Fixed in head (not using NetBSD's patch, since their code seems rather 
different). 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Apr 13 19:51:25 UTC 2014 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=82980 
>Unformatted:
