Bug 2541 - cd (using /bin/sh) may leave you in the wrong directory
Summary: cd (using /bin/sh) may leave you in the wrong directory
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 3.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: tegge
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1997-01-20 22:00 UTC by Tor Egge
Modified: 1998-09-07 20:16 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tor Egge 1997-01-20 22:00:00 UTC
cd (using /bin/sh) may leave you in the wrong directory.

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.
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
---
Comment 1 Steve Price freebsd_committer freebsd_triage 1998-05-31 01:21:37 UTC
Responsible Changed
From-To: freebsd-bugs->tegge

Tor Egge has developed a patch to fix his own PR.  He should 
be committing it soon. :)

Comment 2 tegge freebsd_committer freebsd_triage 1998-09-07 12:04:09 UTC
State Changed
From-To: open->closed

Fixed in revision 1.18 of cd.c and revision 1.4 of cd.h (based upon code
obtained from NetBSD).