NetBSD/bin
kre 70696c0161 Fix (hopefully) the problem reported on current-users by Patrick Welche.
we had incorrect usage of setstackmark()/popstackmark()

There was an ancient idiom (imported from CSRG in 1993) where code
can do:
	setstackmark(&smark); loop until whatever condition {
		/* do lots of code */ popstackmark(&smark);
	} popstackmark(&smark);

The 1st (inner) popstackmark() resets the stack, conserving memory,
The 2nd one is needed just in case the "whatever condition" was never
true, and the first one was never executed.

This is (was) safe as all popstackmark() did was reset the stack.
That could be done over and over again with no harm.

That is, until 2000 when a fix from FreeBSD for another problem was
imported.  That connected all the stack marks as a list (so they can be
located).  That caused the problem, as the idiom was not changed, now
there is this list of marks, and popstackmark() was removing an entry.

It rarely (never?) caused any problems as the idiom was rarely used
(the shell used to do loops like above, mostly, without the inner
popstackmark()).  Further, the stack mark list is only ever used when
a memory block is realloc'd.

That is, until last weekend - with the recent set of changes.

Part of that copied code from FreeBSD introduced the idiom above
into more functions - functions used much more, and with a greater
possibility of stack marks being set on blocks that are realloc'd
and so cause the problem.   In the FreeBSD code, they changed the idiom,
and always do a setstackmark() immediately after the inner popstackmark().
But not for reasons related to a list of stack marks, as in the
intervening period, FreeBSD deleted that, but for another reason.

We do not have their issue, and I did not believe that their
updated idiom was needed (I did some analysis of exactly this issue -
just missed the important part!), and just continued using the old one.
Hence Patrick's core dump....

The solution used here is to split popstackmark() into 2 halves,
popstackmark() continues to do what it has (recently) done,
but is now implemented as a call of (a new func) rststackmark()
which does all the original work of popstackmark - but not removing
the entry from the stack mark list (which remains in popstackmark()).
Then in the idiom above, the inner popstackmark() turns into a call of
rststackmark() so the stack is reset, but the stack mark list is
unchanged.  Tail recursion elimination makes this essentially free.
2018-08-22 20:08:54 +00:00
..
cat Add cross reference to tac(1). 2017-10-02 08:24:17 +00:00
chio typo: unvalid -> invalid 2017-10-16 17:08:35 +00:00
chmod Use Ex. 2017-07-04 06:46:51 +00:00
cp Re-order the code to short circuit all the opens and closes if linking. 2018-07-17 13:04:58 +00:00
csh use SUBDIR.roff suggested by uwe@ 2018-06-10 17:55:11 +00:00
date Remove trailing whitespace and Tn macro. 2018-01-27 18:59:38 +00:00
dd Use Ex. 2017-07-04 06:46:51 +00:00
df Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
domainname Use __dead 2011-08-29 14:51:17 +00:00
echo Use Ex. 2017-07-04 06:46:51 +00:00
ed Prevent shell execution also in the 'r ! dobad' case, pointed out by 2018-06-18 14:56:24 +00:00
expr Add a missing check to handle correctly 0 * 0 in expr(1) 2018-06-27 17:23:36 +00:00
hostname Remove options added in 1.18, commitid: UhxHPgtT2Pzeg4Yw due to some 2014-02-13 12:00:29 +00:00
kill Make arg parsing in kill POSIX compatible with POSIX (XBD 2.12) by 2017-06-26 22:09:16 +00:00
ksh Change typ of tilde_ok from int to unsigned int in ksh(1) 2018-06-12 14:13:55 +00:00
ln When called as "link" (not currently installed that way) always simply 2017-04-22 12:22:31 +00:00
ls Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
mkdir Use Ex. Remove superfluous Pp. 2017-07-04 06:49:35 +00:00
mt Adjust for mandoc output. 2012-03-19 10:48:20 +00:00
mv Use Ex. 2017-07-04 06:50:04 +00:00
pax PR/53362: Thomas Barabosch: Use strlcpy() to prevent theoretical buffer 2018-06-13 15:14:40 +00:00
ps kvm_geterr() already contains errno, use errx. 2018-04-11 18:52:29 +00:00
pwd Use Ex. 2017-07-04 06:50:04 +00:00
rcmd Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
rcp allocate a separate buffer in each call to sink(). 2012-05-07 15:22:54 +00:00
rm Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
rmdir PR/48182: Fix rmdir -p handling of top-level (root) directory. 2017-08-10 22:52:13 +00:00
sh Fix (hopefully) the problem reported on current-users by Patrick Welche. 2018-08-22 20:08:54 +00:00
sleep Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
stty Remove Tn. 2017-10-30 15:38:52 +00:00
sync Drop main() prototype. 2016-09-05 01:00:07 +00:00
test Remove unnecessary Tn. 2017-10-18 18:11:54 +00:00
Makefile
Makefile.inc Default to WARNS=5 2012-03-21 05:47:53 +00:00