From nobody@FreeBSD.org  Tue Feb 12 22:05:38 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 27CE616A418
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 12 Feb 2008 22:05:38 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 1B47613C461
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 12 Feb 2008 22:05:38 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m1CM3M3h054484
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 12 Feb 2008 22:03:22 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m1CM3MU7054483;
	Tue, 12 Feb 2008 22:03:22 GMT
	(envelope-from nobody)
Message-Id: <200802122203.m1CM3MU7054483@www.freebsd.org>
Date: Tue, 12 Feb 2008 22:03:22 GMT
From: Robinson Sathaseevan <robinson@sathas.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pwd reports false path even when change to directory fails
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120571
>Category:       bin
>Synopsis:       pwd(1) reports false path even when change to directory fails
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    stefanf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 12 22:10:00 UTC 2008
>Closed-Date:    Sun Apr 20 18:11:00 UTC 2008
>Last-Modified:  Sun Apr 20 18:11:00 UTC 2008
>Originator:     Robinson Sathaseevan
>Release:        FreeBSD 6.3
>Organization:
None
>Environment:
FreeBSD quad.phub.net.cable.rogers.com 6.3-RELEASE FreeBSD 6.3-RELEASE #0: Wed Jan 16 04:45:45 UTC 2008     root@dessler.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP  i386
>Description:
If a directory has permissions drwx------ and I try to change into it
without being the owner, then the cd command fails. But pwd thinks I
successfully changed into that directory and incorrectly reports as such.
>How-To-Repeat:
$ whoami
roby
$ pwd
/usr/local/etc
$ ls -ld s*
drwx------  2 root  wheel    512 Feb 12 11:30 samba
-rw-r--r--  1 root  wheel   3312 Feb 12 11:34 screenrc
-r--r--r--  1 root  wheel  10313 Feb 12 11:30 smb.conf
-r--r--r--  1 root  wheel  10313 Feb 12 11:30 smb.conf.sample
-r--r-----  1 root  wheel   1148 Feb 12 09:17 sudoers
-r--r--r--  1 root  wheel   1150 Nov 30 20:20 sudoers.default
$ cd samba
cd: can't cd to samba
$ pwd
/usr/local/etc/samba
$ ls -ld s*
drwx------  2 root  wheel    512 Feb 12 11:30 samba
-rw-r--r--  1 root  wheel   3312 Feb 12 11:34 screenrc
-rw-r--r--  1 root  wheel  10313 Feb 12 11:30 smb.conf
-r--r--r--  1 root  wheel  10313 Feb 12 11:30 smb.conf.sample
-r--r-----  1 root  wheel   1148 Feb 12 09:17 sudoers
-r--r--r--  1 root  wheel   1150 Nov 30 20:20 sudoers.default
$ cd ..
$ pwd
/usr/local/etc
$

>Fix:
n/a

>Release-Note:
>Audit-Trail:

From: Volker <volker@vwsoft.com>
To: bug-followup@FreeBSD.org, robinson@sathas.com
Cc:  
Subject: Re: misc/120571: pwd reports false path even when change to directory
 fails
Date: Wed, 13 Feb 2008 00:10:32 +0100

 Tested on 7.0, I see correct behavior using csh and bash, but can
 confirm seeing the same problem when using bourne shell (/bin/sh).
 
 So this seems to be a sh only problem.

From: Volker <volker@vwsoft.com>
To: bug-followup@FreeBSD.org, robinson@sathas.com
Cc:  
Subject: Re: misc/120571: pwd reports false path even when change to directory
 fails
Date: Wed, 13 Feb 2008 00:15:14 +0100

 related PRs:
 bin/64990
 bin/101316

From: "Remko Lodder" <remko@elvandar.org>
To: "Robinson Sathaseevan" <robinson@sathas.com>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: misc/120571: pwd reports false path even when change to 
     directory fails
Date: Wed, 13 Feb 2008 07:43:14 +0100 (CET)

 On Tue, February 12, 2008 11:03 pm, Robinson Sathaseevan wrote:
 
 Interesting because:
 
 remko@freefall.freebsd.org:[/var] pwd
 /var
 remko@freefall.freebsd.org:[/var] whoami
 remko
 remko@freefall.freebsd.org:[/var] cd cron
 -bash: cd: cron: Permission denied
 remko@freefall.freebsd.org:[/var] pwd
 /var
 
 which is on FreeBSD-7.0-STABLE...
 
 
 -- 
 /"\   Best regards,                      | remko@FreeBSD.org
 \ /   Remko Lodder                       | remko@EFnet
  X    http://www.evilcoder.org/          |
 / \   ASCII Ribbon Campaign              | Against HTML Mail and News
 
 
Responsible-Changed-From-To: freebsd-bugs->stefanf 
Responsible-Changed-By: remko 
Responsible-Changed-When: Wed Feb 13 07:00:20 UTC 2008 
Responsible-Changed-Why:  
Hi Stefan, I recall you doing work on /bin/sh for a while, can you have 
a look at this please? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120571 

From: Robinson <robinson@sathas.com>
To: Volker <volker@vwsoft.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/120571: pwd reports false path even when change to directory fails
Date: Wed, 13 Feb 2008 07:39:36 -0800

 Thanks for checking! I will not be using sh any longer anyway.
 
 On Wed, Feb 13, 2008 at 12:10:32AM +0100, Volker wrote:
 > Tested on 7.0, I see correct behavior using csh and bash, but can
 > confirm seeing the same problem when using bourne shell (/bin/sh).
 > 
 > So this seems to be a sh only problem.

From: Robinson <robinson@sathas.com>
To: Remko Lodder <remko@elvandar.org>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: misc/120571: pwd reports false path even when change to directory fails
Date: Wed, 13 Feb 2008 07:39:52 -0800

 Very interesting indeed. I will be moving away from sh anyway.
 
 On Wed, Feb 13, 2008 at 07:43:14AM +0100, Remko Lodder wrote:
 > 
 > On Tue, February 12, 2008 11:03 pm, Robinson Sathaseevan wrote:
 > 
 > Interesting because:
 > 
 > remko@freefall.freebsd.org:[/var] pwd
 > /var
 > remko@freefall.freebsd.org:[/var] whoami
 > remko
 > remko@freefall.freebsd.org:[/var] cd cron
 > -bash: cd: cron: Permission denied
 > remko@freefall.freebsd.org:[/var] pwd
 > /var
 > 
 > which is on FreeBSD-7.0-STABLE...
 > 
 > 
 > -- 
 > /"\   Best regards,                      | remko@FreeBSD.org
 > \ /   Remko Lodder                       | remko@EFnet
 >  X    http://www.evilcoder.org/          |
 > / \   ASCII Ribbon Campaign              | Against HTML Mail and News
 > 
 > 

From: Volker <volker@vwsoft.com>
To: Robinson <robinson@sathas.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/120571: pwd reports false path even when change to directory
 fails
Date: Wed, 13 Feb 2008 18:09:10 +0100

 On 02/13/08 16:39, Robinson wrote:
 > Thanks for checking! I will not be using sh any longer anyway.
 
 Most scripts are written for /bin/sh so even if you aren't using
 /bin/sh, scripts may run into trouble if relying on correct pwd output.
 
 I'm wondering why this hasn't been fixed even while it has been
 reported long time ago.
 
 Here's a quick and dirty fix to that problem:
 
 --- bin/sh/cd.c.orig	2008-02-13 18:05:02.000000000 +0100
 +++ bin/sh/cd.c	2008-02-13 18:05:25.000000000 +0100
 @@ -132,6 +132,7 @@
  				return 0;
  		}
  	}
 +	updatepwd( NULL );
  	error("can't cd to %s", dest);
  	/*NOTREACHED*/
  	return 0;
 
 
 While this little fix solves the problem, the real solution should be
 to find the part where curdir is set but not correctly restored if
 chdir() fails.

From: Robinson <robinson@sathas.com>
To: Volker <volker@vwsoft.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/120571: pwd reports false path even when change to directory fails
Date: Wed, 13 Feb 2008 10:15:29 -0800

 Thanks, I will use the fix until 7.0 STABLE is out and then simply
 upgrade.
 
 As someone also wrote this response to my bug posting:
 
 -- quote --
 remko@freefall.freebsd.org:[/var] pwd
 /var
 remko@freefall.freebsd.org:[/var] whoami
 remko
 remko@freefall.freebsd.org:[/var] cd cron
 -bash: cd: cron: Permission denied
 remko@freefall.freebsd.org:[/var] pwd
 /var
 
 which is on FreeBSD-7.0-STABLE...
 -- end quote --
 
 On Wed, Feb 13, 2008 at 06:09:10PM +0100, Volker wrote:
 > On 02/13/08 16:39, Robinson wrote:
 > > Thanks for checking! I will not be using sh any longer anyway.
 > 
 > Most scripts are written for /bin/sh so even if you aren't using
 > /bin/sh, scripts may run into trouble if relying on correct pwd output.
 > 
 > I'm wondering why this hasn't been fixed even while it has been
 > reported long time ago.
 > 
 > Here's a quick and dirty fix to that problem:
 > 
 > --- bin/sh/cd.c.orig	2008-02-13 18:05:02.000000000 +0100
 > +++ bin/sh/cd.c	2008-02-13 18:05:25.000000000 +0100
 > @@ -132,6 +132,7 @@
 >  				return 0;
 >  		}
 >  	}
 > +	updatepwd( NULL );
 >  	error("can't cd to %s", dest);
 >  	/*NOTREACHED*/
 >  	return 0;
 > 
 > 
 > While this little fix solves the problem, the real solution should be
 > to find the part where curdir is set but not correctly restored if
 > chdir() fails.
State-Changed-From-To: open->patched 
State-Changed-By: stefanf 
State-Changed-When: Sun Feb 24 16:53:19 UTC 2008 
State-Changed-Why:  
Fixed in HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120571 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120571: commit references a PR
Date: Sun, 24 Feb 2008 16:51:01 +0000 (UTC)

 stefanf     2008-02-24 16:50:55 UTC
 
   FreeBSD src repository
 
   Modified files:
     bin/sh               cd.c 
   Log:
   Split updatepwd() into two smaller functions.  The first one, findpwd(),
   computes the new path and the second one, updatepwd(), updates the variables
   PWD, OLDPWD and the path used for the pwd builtin according to the new
   directory.  For a logical directory change, chdir() is now called between
   those two functions, no longer causing wrong values to be stored in PWD etc. if
   it fails.
   
   PR:     64990, 101316, 120571
   
   Revision  Changes    Path
   1.36      +45 -38    src/bin/sh/cd.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: stefanf 
State-Changed-When: Sun Apr 20 18:10:57 UTC 2008 
State-Changed-Why:  
Merged to RELENG_6 and RELENG_7. 

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