1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-24 23:14:14 +00:00
cde/src/cmd/ksh93/tests
Martijn Dekker bdb997415d Fix multiple buffer overflows with justified strings (-L/-R/-Z)
ksh crashed in various different and operating system-dependent
ways when attempting to create or apply justification strings
using typeset -L/-R/-Z, especially if large sizes are used.

The crashes had two immediate causes:
- In nv_newattr(), when applying justification attributes, a buffer
  was allocated for the justified string that was exactly 8 bytes
  longer than the original string. Any larger justification string
  caused a buffer overflow (!!!).
- In nv_putval(), when applying existing attributes to a new value,
  the corresponding memmove() either did not zero-terminate the
  justified string (if the original string was longer than the
  justified string) or could read memory past the original string
  (if the original string was shorter than the justified string).
  Both scenarios can cause a crash.

This commit fixes other minor issues as well, such as a mysterious
8 extra bytes allocated by several malloc/realloc calls. This may
have been some naive attempt to paper over the above bugs. It seems
no one can make any other kind of sense of it.

A readjustment bug with zero-filling was also fixed.

src/cmd/ksh93/sh/name.c:
- nv_putval():
  . Get rid of the magical +8 bytes for malloc and realloc. Just
    allocate one extra byte for the terminating zero.
  . Fix the memmove operation to use strncpy instead, so that
    buffer overflows are avoided in both scenarios described above.
    Also make it conditional upon a size adjustment actually
    happening (i.e. if 'dot' is nonzero).
  . Mild refactoring: combine two 'if(sp)' blocks into one;
    declare variables only used there locally for legibility.
- nv_newattr():
  * Replace the fatally broken "let's allocate string length + 8
    bytes no matter the size of the adjustment" routine with a new
    one based on work by @hyenias (see comments in #142). It is
    efficient with memory, taking into account numeric types,
    growing strings, and shrinking strings.
  * Fix zero-filling in readjustment after changing the initial
    size of a -Z attribute. If the number was zero, all zeros were
    still skipped, leaving an empty string.

Thanks to @hyenias for originally identifying this breakage and
laying the groundwork for fixing nv_newattr(), and to @lijog for
the crash analysis that revealed the key to the nv_putval() fix.

Resolves: https://github.com/ksh93/ksh/issues/142
Resolves: https://github.com/ksh93/ksh/issues/181
2021-02-20 13:05:38 +00:00
..
alias.sh Fix a crash on unsetting preset alias (re: ddaa145b) (#133) 2020-09-18 11:17:20 +01:00
append.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
arith.sh Produce IEEE compliant output from pow() despite platform deviations 2021-02-12 13:23:16 +00:00
arrays.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
arrays2.sh Fix disabling SHOPT_FIXEDARRAY (re: 2182ecfa) 2021-02-10 04:48:56 +00:00
attributes.sh Fix multiple buffer overflows with justified strings (-L/-R/-Z) 2021-02-20 13:05:38 +00:00
basic.sh DEBUG trap: restore status 2 trigger to skip command (re: d00b4b39) 2021-02-20 05:13:51 +00:00
bracket.sh github: Re-disable Mac CI runner (re: 5c389035) 2021-02-13 06:58:30 +00:00
builtins.sh Make 'read' compatible with Shift-JIS 2021-02-18 16:07:12 +00:00
case.sh More 'case' regression tests (re: e37aa358) 2021-02-16 13:36:50 +00:00
comvar.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
comvario.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
coprocess.sh regress test tweaks 2020-10-03 00:32:32 +02:00
cubetype.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
enum.sh Correctly block invalid values for arrays of an enum type 2021-02-01 16:57:43 +00:00
exit.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
expand.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
functions.sh sleep: guarantee sleeping specified time at minimum (#174) 2021-02-14 07:27:04 +00:00
glob.sh Fix compile/regress fails on compiling without SHOPT_* options 2021-02-08 22:02:45 +00:00
grep.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
heredoc.sh fix typos: descritor -> descriptor 2020-10-05 18:39:49 +02:00
io.sh Fix many spelling errors and word repetitions (#188) 2021-02-20 03:22:24 +00:00
jobs.sh test/jobs.sh: use slightly more widely supported ps -o format 2021-02-15 15:41:31 +00:00
leaks.sh Implement leak detection on UnixWare (#172) 2021-02-13 00:52:54 +00:00
locale.sh Make 'read' compatible with Shift-JIS 2021-02-18 16:07:12 +00:00
math.sh Fix compile/regress fails on compiling without SHOPT_* options 2021-02-08 22:02:45 +00:00
nameref.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
namespace.sh Fix compile/regress fails on compiling without SHOPT_* options 2021-02-08 22:02:45 +00:00
options.sh tests/options.sh: add forgotten SHOPT_BRACEPAT check (re: af5f7acf) 2021-02-15 01:57:17 +00:00
path.sh Fix many spelling errors and word repetitions (#188) 2021-02-20 03:22:24 +00:00
pointtype.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
pty.sh Fix emacs backslash escaping behavior (#179) 2021-02-17 14:29:12 +00:00
quoting.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
quoting2.sh Make 'read' compatible with Shift-JIS 2021-02-18 16:07:12 +00:00
readcsv.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
recttype.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
restricted.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
return.sh move exit/return tests from basic.sh to return.sh (re: 092b90da) 2021-02-14 06:32:57 +00:00
select.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
shtests shtests: Stop requiring a tty 2021-02-13 05:55:27 +00:00
sigchld.sh tests/sigchild.sh: increase a sleep to prevent very rare intermittent fail 2020-09-18 20:06:34 +02:00
signal.sh Fix signal/trap behaviour in ksh functions (rhbz#1454804) 2020-09-29 03:16:39 +02:00
statics.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
subshell.sh Update comsub-with-alias anti-leak hack (re: fe20311f) 2021-02-18 23:35:20 +00:00
substring.sh Fix compile/regress fails on compiling without SHOPT_* options 2021-02-08 22:02:45 +00:00
tilde.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
timetype.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
treemove.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
types.sh typeset: add error msgs for incompatible options; improve usage msg 2021-01-21 09:36:10 +00:00
variables.sh Fix many spelling errors and word repetitions (#188) 2021-02-20 03:22:24 +00:00
vartree1.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00
vartree2.sh shtests: cd to each test set's temp dir before running 2020-09-02 06:02:40 +01:00