1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/sh
Martijn Dekker 61e0f90460 Yet more fixes for subshell directory handling (re: feaf718f)
There were still problems left after the previous commit. On at
least one system (QNX i386), the following regression test crashed:

src/cmd/ksh93/test/subshell.c
900     got=$( { "$SHELL" -c '(cd /; (cd /)); print -r -- "PWD=$PWD"'; } 2>&1 )

A backtrace done on the core dunp pointed to the free() call here:

src/cmd/ksh93/bltins/cd_pwd.c
90      if(oldpwd && oldpwd!=shp->pwd && oldpwd!=e_dot)
91              free(oldpwd);

Analysis: The interaction between $PWD, sh.pwd aka shp->pwd, and
the path_pwd() function is a mess. path_pwd() usually returns a
freeable value, but not always. sh.pwd is sometimes a pointer to
the value of $PWD, but not always (e.g. when you unset PWD or
assign to it). Instead of debugging the exact cause of the crash, I
think it is better to make this work in a more consistent way.

As of this commit:
1. sh.pwd keeps its own copy of the PWD, independently of the PWD
   variable. The old value must always be freed immediately before
   assigning a new one. This is simple and consistent, reducing the
   chance of bugs at negligible cost.
2. The PWD variable is no longer given the NV_NOFREE attribute
   because its value no longer points to sh.pwd. It is now a
   variable like any other.

src/cmd/ksh93/sh/path.c: path_pwd():
- Do not give PWDNOD the NV_NOFREE attribute.
- Give sh.pwd its own copy of the PWD by strdup'ing PWDNOD's value.

src/cmd/ksh93/bltins/cd_pwd.c: b_cd():
- Since sh.pwd is now consistently freed before giving it a new
  value and at no other time, oldpwd must not be freed any longer
  and can become a regular non-static variable.
- If the PWD needs reinitialising, call path_pwd() to do it.

src/cmd/ksh93/sh/subshell.c: sh_subshell():
- Systems with fchdir(2): Always restore the PWD upon exiting a
  non-subshare subshell. The check to decide whether or not to
  restore it was unsafe: it was not restored if the current PWD
  pointer and value was identical to the saved one, but a directory
  can be deleted and recreated under the same name.
- Systems without fchdir(2) (if any exist):
  . Entry: Fork if the PWD is nonexistent or has no x permission.
  . Restore: Only chdir back if the subshell PWD was changed.
  That's probably the best we can do. It remains inherently unsafe.
  We should probably just require fchdir(2) at some point.
2021-04-20 05:39:10 +01:00
..
args.c Fix handling of '--posix' and '--default' (#265) 2021-04-09 23:26:07 +01:00
arith.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
array.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
defs.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
deparse.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00:00
expand.c Add --globcasedetect shell option for globbing and completion 2021-03-22 18:45:19 +00:00
fault.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
fcin.c Fix many GCC -Wimplicit-fallthrough warnings (#243) 2021-03-30 21:49:20 +01:00
init.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
io.c Backport bugfix for BUG_CSUBSTDO from ksh93v- 2012-08-24 (#259) 2021-04-08 13:24:17 +01:00
jobs.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
lex.c lex.c: simplify fmttoken() by using the stack (re: 3255aed2) 2021-04-09 17:36:29 +01:00
macro.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
main.c Fix <>; redirection for final command exec optimization (#277) 2021-04-15 18:29:50 +01:00
name.c Correct memory fault when removing default nameref KSH_VERSION (#271) 2021-04-13 03:15:34 +01:00
nvdisc.c nv_disc(NV_LAST) loses trailing shell context from discipline stack (#276) 2021-04-15 14:41:32 +01:00
nvtree.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00:00
nvtype.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
parse.c Allow invoking path-bound built-in commands by direct path or preceding PATH assignment (#275) 2021-04-15 04:08:12 +01:00
path.c Yet more fixes for subshell directory handling (re: feaf718f) 2021-04-20 05:39:10 +01:00
pmain.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
shcomp.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
streval.c Reset arithmetic recursion level on all errors (re: 264ba48b) 2021-04-11 01:25:19 +01:00
string.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
subshell.c Yet more fixes for subshell directory handling (re: feaf718f) 2021-04-20 05:39:10 +01:00
suid_exec.c Fix more compiler warnings, typos and other minor issues (#260) 2021-04-08 19:58:07 +01:00
tdump.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
timers.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
trestore.c '#if 0' cleanup 2020-08-30 04:51:20 +01:00
waitevent.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
xec.c Further fix '<>;' and fix crash on 32-bit systems (re: 6701bb30) 2021-04-17 21:56:39 +01:00