1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00
cde/src/lib/libast/misc
Martijn Dekker 56805b25af Fix leak and crash upon defining functions in subshells
A memory leak occurred upon leaving a virtual subshell if a
function was defined within it. If this was done more than 32766
(= 2^15-2 = the 'short' max value - 1) times, the shell crashed.
Discussion and reproducer: https://github.com/ksh93/ksh/issues/114

src/cmd/ksh93/sh/subshell.c: table_unset():
- A subshell-defined function was never freed because a broken
  check for autoloaded functions (which must not be freed[*]). It
  looked for an initial '/' in the canonical path of the script
  file that defined the function, but that path is also stored for
  regular functions. Now use a check that executes nv_search() in
  fpathdict, the same method used in _nv_unset() in name.c for a
  regular function unset.

src/cmd/ksh93/bltins/misc.c: b_dot_cmd():
- Fix an additional memory leak introduced in bd88cc7f, that caused
  POSIX functions (which are run with b_dot_cmd() like dot scripts)
  to leak extra. This fix avoids both the crash fixed there and the
  memory leak by introducing a 'tofree' variable remembering the
  filename to free. Thanks to Johnothan King for the patch.

src/lib/libast/include/stk.h,
src/lib/libast/misc/stk.c,
src/lib/libast/man/stk.3,
src/lib/libast/man/stak.3:
- Make the stack more resilient by extending the stack reference
  counter 'stkref' from (signed) short to unsigned int. On modern
  systems with 32-bit ints, this extends the maximum number of
  elements on a stack from 2^15-1==32767 to 2^32-1==4294967295.
  The ref counter can never be negative, so there is no reason for
  signedness. sizeof(int) is defined as the size of a single CPU
  word, so this should not affect performance at all.
     On a 16-bit system (not that ksh still compiles there), this
  doubles the max number of entries to 2^16-1=65535.

src/cmd/ksh93/tests/leaks.sh:
- Add leak regression tests for ksh functions, POSIX functions, dot
  scripts run with '.', and dot scripts run with 'source'.

src/cmd/ksh93/tests/path.sh:
- Add an output builtin with a redirect to an autoloaded function
  so that a crash[*] is triggered if the check for an autoloaded
  function is ever removed from table_unset(), as was done in ksh
  93v- (which crashed).

[*] Freeing autoloaded functions after leaving a virtual subshell
    causes a crashing bug: https://github.com/att/ast/issues/803

Co-authored-by: Johnothan King <johnothanking@protonmail.com>
Fixes: https://github.com/ksh93/ksh/issues/114
2020-08-14 00:25:31 +01:00
..
astintercept.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
cmdarg.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
cmdlib.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
conformance.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
debug.c Fix the max precision of the 'time' keyword (#72) 2020-07-14 22:48:04 +01:00
error.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
errorf.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
errormsg.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
errorx.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
fastfind.c Fix a large number of typos and other problems (#110) 2020-08-07 00:50:11 +01:00
findlib.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
fmtrec.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
fts.c Remove vestigial 3DFS support code (re: f88f302c) 2020-07-17 05:04:03 +01:00
ftwalk.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
ftwflags.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
getcwd.c Remove vestigial 3DFS support code (re: f88f302c) 2020-07-17 05:04:03 +01:00
getenv.c Remove vestigial 3DFS support code (re: f88f302c) 2020-07-17 05:04:03 +01:00
glob.c Skip '.' and '..' when globbing patterns like .* 2020-08-10 00:35:53 +01:00
intercepts.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
magic.c Fix 80 typos in comments 2020-06-12 01:45:12 +02:00
magic.tab Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
mime.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
mimelib.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
mimetype.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
optctx.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
optesc.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
optget.c Fix annoying usage/--help/--man message corruption 2020-07-16 05:13:53 +01:00
optjoin.c Fix 80 typos in comments 2020-06-12 01:45:12 +02:00
optlib.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
procclose.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
procfree.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
proclib.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
procopen.c Fix a large number of typos and other problems (#110) 2020-08-07 00:50:11 +01:00
procrun.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
recfmt.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
reclen.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
recstr.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
setenviron.c Remove vestigial 3DFS support code (re: f88f302c) 2020-07-17 05:04:03 +01:00
sigcrit.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
sigdata.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
signal.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
stack.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
state.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
stk.c Fix leak and crash upon defining functions in subshells 2020-08-14 00:25:31 +01:00
systrace.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
translate.c Fix 80 typos in comments 2020-06-12 01:45:12 +02:00
univdata.c Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00
univlib.h Version: 2012-08-01-master 2016-01-11 15:54:23 -05:00