Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ksh93: "OLDPWD=/dir cd -" doesn't take you to /dir #8

Closed
stephane-chazelas opened this issue Apr 24, 2016 · 1 comment
Closed

ksh93: "OLDPWD=/dir cd -" doesn't take you to /dir #8

stephane-chazelas opened this issue Apr 24, 2016 · 1 comment
Labels

Comments

@stephane-chazelas
Copy link

$ OLDPWD=/bin ksh93 -c 'OLDPWD=/tmp cd -'
/bin

Expected:

/tmp

Things like CDPATH=/usr cd bin are OK though.

(on ksh93u on Debian)

@siteshwar
Copy link
Contributor

Still reproducible. I will fix it.

siteshwar added a commit that referenced this issue Mar 21, 2018
ksh does not check if OLDPWD variable is overriden while going to
previous directory through 'cd -'. For e.g.

OLDPWD=/bin ksh -c 'OLDPWD=/tmp cd -'

takes to '/bin' directory.

This commit fixes it.

Resolves: #8
siteshwar added a commit that referenced this issue Mar 21, 2018
Add test cases to check if overriden OLDPWD variable is recognized while
executing 'cd -'.

Related: #8
JohnoKing added a commit to JohnoKing/ksh that referenced this issue Mar 31, 2021
This bug was first reported at <att#8>.
The 'cd' command currently takes the value of $OLDPWD from the wrong
scope. In the following example 'cd -' will change the directory to /bin
instead of /tmp:
    $ OLDPWD=/bin ksh93 -c 'OLDPWD=/tmp cd -'
    /bin

src/cmd/ksh93/bltins/cd_pwd.c:
- Backport the ksh2020 bugfix which uses sh_scoped() to obtain the
  correct value of $OLDPWD.

src/cmd/ksh93/tests/builtins.sh:
- Backport the ksh2020 regression tests for 'cd -' when $OLDPWD is set.
McDutchie added a commit to ksh93/ksh that referenced this issue Apr 2, 2021
This bug was first reported at <att#8>.
The 'cd' command currently takes the value of $OLDPWD from the
wrong scope. In the following example 'cd -' will change the
directory to /bin instead of /tmp:

    $ OLDPWD=/bin ksh93 -c 'OLDPWD=/tmp cd -'
    /bin

src/cmd/ksh93/bltins/cd_pwd.c:
- Use sh_scoped() to obtain the correct value of $OLDPWD.
- Fix a use-after-free bug. Make the 'oldpwd' variable a static
  char that points to freeable memory. Each time cd is used, this
  variable is freed if it points to a freeable memory address and
  isn't also a pointer to shp->pwd.

src/cmd/ksh93/sh/path.c: path_pwd():
- Simplify and add comments.
- Scope $PWD properly.

src/cmd/ksh93/tests/builtins.sh,
src/cmd/ksh93/tests/leaks.sh:
- Backport the ksh2020 regression tests for 'cd -' when $OLDPWD is
  set.
- Add test for $OLDPWD and $PWD after subshare.
- Add test for $PWD after 'cd'.
- Add test for possible memory leak.
- Add testing for 'unset' on OLDPWD and PWD.

src/cmd/ksh93/COMPATIBILITY:
- Add compatibility note about changes to $PWD and $OLDPWD.

Co-authored-by: Martijn Dekker <[email protected]>
gkamat pushed a commit to gkamat/ast that referenced this issue Apr 28, 2021
Backport the ksh2020 fix for timezone name determination

Partial fix for att#6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants