From Tor.Egge@idt.ntnu.no  Mon Jan 20 13:55:42 1997
Received: from pat.idt.unit.no (0@pat.idt.unit.no [129.241.103.5])
          by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id NAA01114
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Jan 1997 13:55:41 -0800 (PST)
Received: from bitbucket.idt.ntnu.no (bitbucket.idt.ntnu.no [129.241.111.175])
          by pat.idt.unit.no (8.8.4/8.8.4) with ESMTP
	  id WAA01088 for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Jan 1997 22:55:35 +0100 (MET)
Received: (from tegge@localhost) by bitbucket.idt.ntnu.no (8.8.4/8.8.3) id WAA14878; Mon, 20 Jan 1997 22:55:34 +0100 (CET)
Message-Id: <199701202155.WAA14878@bitbucket.idt.ntnu.no>
Date: Mon, 20 Jan 1997 22:55:34 +0100 (CET)
From: Tor Egge <Tor.Egge@idt.ntnu.no>
Reply-To: Tor.Egge@idt.ntnu.no
To: FreeBSD-gnats-submit@freebsd.org
Subject: cd (using /bin/sh) may leave you in the wrong directory
X-Send-Pr-Version: 3.2

>Number:         2541
>Category:       bin
>Synopsis:       cd (using /bin/sh) may leave you in the wrong directory
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tegge
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 20 14:00:00 PST 1997
>Closed-Date:    Mon Sep  7 12:04:09 1998
>Last-Modified:  Mon Sep  7 12:16:35 PDT 1998
>Originator:     Tor Egge
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Norwegian University of Science and Technology, Trondheim, Norway

>Environment:

FreeBSD ikke.idt.unit.no 3.0-CURRENT FreeBSD 3.0-CURRENT #0: Mon Jan 20 21:59:08 MET 1997     root@ikke.idt.unit.no:/usr/src/sys-UP/compile/TEGGE  i386

>Description:

cd (using /bin/sh) may leave you in the wrong directory.

>How-To-Repeat:

Run the following shell script:

---
#!/bin/sh
cd /tmp
rm -rf /tmp/good /tmp/bad
mkdir good
mkdir good/some
mkdir good/etc
echo  "Test OK" > good/etc/FILE
mkdir bad
mkdir bad/etc
echo  "Test failed" > bad/etc/FILE
ln -s ../good/some bad/some
cd /tmp/bad/some/../etc
cat FILE
/bin/pwd
cd ..
/bin/pwd
cd /tmp
rm -rf /tmp/good /tmp/bad
---


>Fix:
	
Don't blindly eliminate `..' in the target directory name by also 
eliminating the previous component. If the previous component was 
a symbolic link, the elimination might be bogus.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->tegge 
Responsible-Changed-By: steve 
Responsible-Changed-When: Sat May 30 17:21:37 PDT 1998 
Responsible-Changed-Why:  
Tor Egge has developed a patch to fix his own PR.  He should 
be committing it soon. :)

State-Changed-From-To: open->closed
State-Changed-By: tegge
State-Changed-When: Mon Sep  7 12:04:09 1998
State-Changed-Why:
Fixed in revision 1.18 of cd.c and revision 1.4 of cd.h (based upon code
obtained from NetBSD).
>Unformatted:
