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

Check if OLDPWD variable is overriden while executing 'cd -' #441

Merged
merged 2 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cmd/ksh93/bltins/cd_pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ int b_cd(int argc, char *argv[], Shbltin_t *context) {
dir = nv_getval(HOME);
if (!dir && (pw = getpwuid(geteuid()))) dir = pw->pw_dir;
} else if (*dir == '-' && dir[1] == 0) {
dir = nv_getval(opwdnod);
dir = sh_scoped(shp, opwdnod)->nvalue.cp;
}

if (!dir || *dir == 0) errormsg(SH_DICT, ERROR_exit(1), argc == 2 ? e_subst + 4 : e_direct);
Expand Down Expand Up @@ -252,7 +252,7 @@ int b_cd(int argc, char *argv[], Shbltin_t *context) {
errormsg(SH_DICT, ERROR_system(1), "%s:", dir);
}
success:
if (dir == nv_getval(opwdnod) || argc == 2) dp = dir; // print out directory for cd -
if (dir == sh_scoped(shp, opwdnod)->nvalue.cp || argc == 2) dp = dir; // print out directory for cd -
if (pflag) {
dir = stakptr(PATH_OFFSET);
dir = pathcanon(dir, PATH_MAX, PATH_ABSOLUTE | PATH_PHYSICAL);
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/ksh93/tests/builtins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,16 @@ else
err_exit 'cannot cd to ~{fd} when fd is /dev'
fi

mkdir $tmp/oldpwd
OLDPWD=$tmp/oldpwd
cd -
[[ $PWD == "$tmp/oldpwd" ]] || err_exit "cd - does not recognize overridden OLDPWD variable"

[[ $(pwd -f $fd) == /dev ]] || err_exit "pwd -f $fd should be /dev"
cd $tmp
[[ $(OLDPWD="$tmp/oldpwd" cd -) == "$tmp/oldpwd" ]] ||
err_exit "cd - does not recognize overridden OLDPWD variable if it is overridden in new scope"

[[ $(pwd -f $fd) == /dev ]] || err_exit "pwd -f $fd should be /dev"

# Below test fails on OpenSUSE
echo "TODO: Skipping test - 'cd with no arguments fails if HOME is unset'. It should be fixed later."
Expand Down