summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-21 16:14:25 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-21 16:14:25 +0000
commit748d0319758b319897e6839169f9b45e27d030da (patch)
treeea8a059241e37de6227195456ad1f436e186e93a
parent6939ed3cf1934623e887fc392bf4bb8126dfac6f (diff)
downloadmandoc-748d0319758b319897e6839169f9b45e27d030da.tar.gz
Avoid a use after free when the target node is deleted during validation.
Bug reported by jsg@.
-rw-r--r--mdoc_macro.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/mdoc_macro.c b/mdoc_macro.c
index f2c7d78e..05234250 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -291,18 +291,21 @@ rew_pending(struct roff_man *mdoc, const struct roff_node *n)
for (;;) {
rew_last(mdoc, n);
- switch (n->type) {
- case ROFFT_HEAD:
- roff_body_alloc(mdoc, n->line, n->pos, n->tok);
- return;
- case ROFFT_BLOCK:
- break;
- default:
- return;
- }
-
- if ( ! (n->flags & MDOC_BROKEN))
- return;
+ if (mdoc->last == n) {
+ switch (n->type) {
+ case ROFFT_HEAD:
+ roff_body_alloc(mdoc, n->line, n->pos,
+ n->tok);
+ return;
+ case ROFFT_BLOCK:
+ break;
+ default:
+ return;
+ }
+ if ( ! (n->flags & MDOC_BROKEN))
+ return;
+ } else
+ n = mdoc->last;
for (;;) {
if ((n = n->parent) == NULL)