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 997ad43bbf Properly fix $LINENO crash on ARM (re: 23b7a163) and other bugs
The typecast fix was insufficient, avoiding the crash only when
compiling with optimisation disabled. The real problem is that
put_lineno() was passed a misaligned pointer, and that the value
didn't actually contain a double but a string. The bug occurred
when restoring the LINENO value upon exiting a virtual subshell.

Thanks to Harald van Dijk for figuring out the fix.

src/cmd/ksh93/sh/subshell.c: nv_restore():
- When restoring a special variable as defined by nv_cover(),
  do not pass either the np->nvflag bits or NV_NOFREE. Why?
  * The np->nvflag bits are not needed. They are also harmful
    because they may include the NV_INTEGER bit. This is set
    when the value is numeric. However, nv_getval() always
    returns the value in string form, converting it if it is
    numeric. So the NV_INTEGER flag should never be passed
    to nv_putval() when it uses the result of nv_getval().
  * According to nval.3, the NV_NOFREE flag stops nv_putval() from
    creating a copy of the value. But this should be unnecessary
    because the earlier _nv_unset(mp,NV_RDONLY|NV_CLONE) should
    ensure there is no previous value. In addition, the NV_NOFREE
    flag triggered another bug that caused the value of SECONDS to
    be corrupted upon restoring it when exiting a virtual subshell.
- When restoring a regular variable, copy the entire nvalue union
  and not just the 'cp' member. In practice this worked because
  no current member of the nvalue union is larger than a pointer.
  However, there is no guarantee it will stay that way.

src/cmd/ksh93/tests/leaks.sh:
- Add disabled test for a memory leak that was discovered in the
  course of dealing with this bug. The fix doesn't introduce or
  influence it. It will have to be dealt with later.

src/cmd/ksh93/tests/locale.sh:
- Add test for restoring locale on leaving virtual subshell.
  https://github.com/ksh93/ksh/issues/253#issuecomment-815290154

src/cmd/ksh93/tests/variables.sh:
- Test against corruption of SECONDS on leaving virtual subshell.
  https://github.com/ksh93/ksh/issues/253#issuecomment-815191052

Co-authored-by: Harald van Dijk <harald@gigawatt.nl>
Progresses: https://github.com/ksh93/ksh/issues/253
2021-04-08 00:56:09 +01:00
..
args.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
arith.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
array.c Backport bugfixes for arrays of 'enum' types from ksh 93v- beta 2021-04-06 06:33:32 +01:00
defs.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00: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 Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
fcin.c Fix many GCC -Wimplicit-fallthrough warnings (#243) 2021-03-30 21:49:20 +01:00
init.c Fix implicit typecast mess in $LINENO discipline functions 2021-04-07 15:53:23 +01:00
io.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
jobs.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
lex.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
macro.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
main.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
name.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
nvdisc.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
nvtree.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00:00
nvtype.c Backport bugfixes for arrays of 'enum' types from ksh 93v- beta 2021-04-06 06:33:32 +01:00
parse.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00
path.c Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +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 Hardening of readonly variables (#239) 2021-04-05 06:43:19 +01:00
string.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00:00
subshell.c Properly fix $LINENO crash on ARM (re: 23b7a163) and other bugs 2021-04-08 00:56:09 +01:00
suid_exec.c Fix various minor problems and update the documentation (#237) 2021-03-21 14:39:03 +00: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 Introduce usage of __builtin_unreachable() and noreturn (#248) 2021-04-05 00:28:24 +01:00