From 7c8094a3ac439b9d9cd5ef5c0d77744db2544287 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 19 Nov 2011 13:17:45 +0000 Subject: Avoid a NULL pointer access if an .Rs block body contains nothing but invalid nodes. Output still differs a lot from groff, but at least let's not crash. Problem found and patch provided by joerg@, thanks! --- usr.bin/mandoc/mdoc_validate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'usr.bin') diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 9d8827d4b97..f3e3479a329 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.97 2011/11/16 19:47:58 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.98 2011/11/19 13:17:44 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -1689,6 +1689,14 @@ post_rs(POST_ARGS) mdoc_node_delete(mdoc, nn); } + /* + * Nothing to sort if only invalid nodes were found + * inside the `Rs' body. + */ + + if (NULL == mdoc->last->child) + return(1); + /* * The full `Rs' block needs special handling to order the * sub-elements according to `rsord'. Pick through each element -- cgit v1.2.3