diff --git a/NEWS b/NEWS index bee1a3506e74..d797bd6f29ee 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,12 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library. - [v1.1] The emacs ^Y command now accepts a numeric parameter. For example, ESC 10 ^Y will now "yank" (paste) the latest deleted text 10 times. +- Fixed a crash that could occur if a discipline function was first + assigned to a variable in a virtual subshell before the variable was + scoped to that subshell, then upon subshell completion another discipline + function of the same type was assigned to that selfsame variable in the + parent shell. + 2024-12-25: - The dirname path-bound built-in now accepts multiple operands. diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index e7cb7046eec3..e4467c91bc57 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -2485,7 +2485,18 @@ int sh_exec(const Shnode_t *t, int flags) if(npv) { if(!sh.mktype) + { + if(sh.subshell && !sh.subshare) + { + /* + * When a variable is given a discipline function in + * a subshell, the variable must be scoped to the + * subshell before nvfun is set to the discipline. + */ + sh_assignok(npv, 1); + } cp = nv_setdisc(npv,cp,np,(Namfun_t*)npv); + } if(!cp) { errormsg(SH_DICT,ERROR_exit(1),e_baddisc,fname);