cdesktopenv/src/cmd
Martijn Dekker f24040ee45 Fix use after free in sh_funstaks() (re: 69d37d5e)
The referenced commit introduced the NIL (NULL) assignment in:

	stakdelete(slpold->slptr);
	slpold->slptr = NIL(Stak_t*);

First the stack is closed/freed with stakdelete() a.k.a.
stkclose(), then its pointer is reset. Looks correct, right?

Wrong: slpold may itself be in the allocated region that
slpold->slptr points to. That's because we're dealing with a linked
list of stacks, in which a pointer on each stack points to the next
stack. So there are scenarios in which, after the stakdelete()
call, dereferencing slpold is a use after free.

Most systems quietly tolerate this use after free. But, according
to @JohnoKing's testing, this bug was causing 23 crashes in the
regression tests after compiling ksh with AddressSanitizer enabled.

src/cmd/ksh93/sh/parse.c: sh_funstaks():
- Save the value of slpold->slptr and reset that pointer before
  calling stakdelete() a.k.a. stkclose().

Resolves: https://github.com/ksh93/ksh/issues/517
2022-08-19 15:55:10 +01:00
..
INIT package install: fix a non-POSIX-ism (re: dde4451b) 2022-08-02 22:44:55 +02:00
builtin Update author attributions in all source files 2022-07-31 00:47:08 +02:00
ksh93 Fix use after free in sh_funstaks() (re: 69d37d5e) 2022-08-19 15:55:10 +01:00
Mamfile More misc. tweaks and cleanups 2022-07-14 17:34:08 +02:00