When the first child of the node being validated gets deleted during
authorschwarze <schwarze@openbsd.org>
Mon, 18 Aug 2014 16:26:13 +0000 (16:26 +0000)
committerschwarze <schwarze@openbsd.org>
Mon, 18 Aug 2014 16:26:13 +0000 (16:26 +0000)
commitdaac8107b10b6711c0940a4621c8d1220e0d4092
tree7e8b3982436835d35235359c90e05ec5794a00d5
parent9c61b873a261e077bd1b502dbbf1cd84ea22fe21
When the first child of the node being validated gets deleted during
validation, man_node_unlink() switches to MAN_NEXT_CHILD.  After
that, we have to switch back to MAN_NEXT_SIBLING after completing
validation, or subsequent parsing would add content into an already
closed node, clobbering potentially existing children, causing
information loss and a memory leak.  Bug found by kristaps@ with
valgrind in groff(7) on Mac OS X.

Note that the switch back must be conditional, for if the node being
validated itself gets deleted, we must *not* go to MAN_NEXT_SIBLING,
which would not only yield wrong results in general but also crash
in malformed manuals having an empty paragraph before the first .SH,
for example OpenBSD c++filt(1).

While here, add the missing <sys/types.h> as required before mandoc.h.
regress/usr.bin/mandoc/man/RS/Makefile
regress/usr.bin/mandoc/man/RS/broken.in [new file with mode: 0644]
regress/usr.bin/mandoc/man/RS/broken.out_ascii [new file with mode: 0644]
regress/usr.bin/mandoc/man/RS/broken.out_lint [new file with mode: 0644]
regress/usr.bin/mandoc/man/SH/Makefile
regress/usr.bin/mandoc/man/SH/empty_before.in [new file with mode: 0644]
regress/usr.bin/mandoc/man/SH/empty_before.out_ascii [new file with mode: 0644]
regress/usr.bin/mandoc/man/SH/empty_before.out_lint [new file with mode: 0644]
usr.bin/mandoc/man_macro.c