From 4b457fd6fb8121c75e7d748648d2599ee902f848 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 27 Dec 2017 09:34:53 +0000 Subject: Fix a segfault on bad input files. I ran into this as a knock-on effect from having misspelled a section name identifier (i.e. I had a \k{nonexistent-name} in my document). Before I fix the document, I should fix the segfault! --- bk_html.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bk_html.c b/bk_html.c index f6b7f4b..294ac7a 100644 --- a/bk_html.c +++ b/bk_html.c @@ -2946,11 +2946,20 @@ static void html_href(htmloutput *ho, htmlfile *thisfile, rdaddc(&rs, '#'); rdaddsc(&rs, targetfrag); } + + /* If _neither_ of those conditions were true, we don't have a URL + * at all and will segfault when we pass url==NULL to element_attr. + * + * I think this can only occur as a knock-on effect from an input + * file error, but we still shouldn't crash, of course. */ + url = rs.text; element_open(ho, "a"); - element_attr(ho, "href", url); - sfree(url); + if (url) { + element_attr(ho, "href", url); + sfree(url); + } } static void html_fragment(htmloutput *ho, char const *fragment) -- cgit v1.1