tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: mdocml: Convert an assert into an explicit check.
Date: Sat, 3 Dec 2011 22:41:57 +0100	[thread overview]
Message-ID: <20111203214157.GH17667@iris.usta.de> (raw)
In-Reply-To: <20111120191718.GA24971@britannica.bec.de>

Hi Joerg,

Joerg Sonnenberger wrote on Sun, Nov 20, 2011 at 08:17:18PM +0100:
> On Sun, Nov 20, 2011 at 01:27:10PM +0100, Ingo Schwarze wrote:

>> It's not mandoc(1) that is crashing on that one, but groff(1);

> mandoc(1) was was crashing on this. I gave the complete input file.

Ah, with that bit of information, i was able to reproduce and
finally came round to preparing a proper fix; thanks for the report.
I'm giving a patch against bsd.lv below; in OpenBSD, all that is needed
is removing the "assert(MAN_ROOT != m->last->type);" from function
man_unscope, file man_macro.c.

That function just works fine even when the syntax tree is completely
empty, only containing the ROOT node.  It is important to *NOT*
return early, but to continue through the whole function and execute
the man_valid_post(m) near the end - otherwise, you will end up
with NULL pointers in the meta structure and provoke the crashes
you observed.

OK?
  Ingo


Index: man_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_html.c,v
retrieving revision 1.84
diff -u -p -r1.84 man_html.c
--- man_html.c	18 Nov 2011 17:05:50 -0000	1.84
+++ man_html.c	3 Dec 2011 21:37:58 -0000
@@ -305,8 +305,7 @@ man_root_pre(MAN_ARGS)
 	if (m->vol)
 		(void)strlcat(b, m->vol, BUFSIZ);
 
-	snprintf(title, BUFSIZ - 1, "%s(%s)", m->title ? m->title : "",
-	    m->msec ? m->msec : "");
+	snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
 
 	PAIR_SUMMARY_INIT(&tag[0], "Document Header");
 	PAIR_CLASS_INIT(&tag[1], "head");
@@ -360,8 +359,7 @@ man_root_post(MAN_ARGS)
 	PAIR_CLASS_INIT(&tag[0], "foot-date");
 	print_otag(h, TAG_TD, 1, tag);
 
-	if (m->date)
-		print_text(h, m->date);
+	print_text(h, m->date);
 	print_stagq(h, tt);
 
 	PAIR_CLASS_INIT(&tag[0], "foot-os");
Index: man_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_macro.c,v
retrieving revision 1.69
diff -u -p -r1.69 man_macro.c
--- man_macro.c	18 Nov 2011 17:06:19 -0000	1.69
+++ man_macro.c	3 Dec 2011 21:37:58 -0000
@@ -120,8 +120,6 @@ man_unscope(struct man *m, const struct 
 
 	assert(to);
 
-	if (MAN_ROOT == m->last->type)
-		return(1);
 	m->next = MAN_NEXT_SIBLING;
 
 	/* LINTED */
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.124
diff -u -p -r1.124 man_term.c
--- man_term.c	18 Nov 2011 17:04:06 -0000	1.124
+++ man_term.c	3 Dec 2011 21:37:58 -0000
@@ -969,9 +969,8 @@ print_man_foot(struct termp *p, const vo
 	term_vspace(p);
 	term_vspace(p);
 	term_vspace(p);
-	snprintf(title, BUFSIZ, "%s(%s)", meta->title ? meta->title : "",
-	    meta->msec ? meta->msec : "");
-	datelen = term_strlen(p, meta->date ? meta->date : "");
+	snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec);
+	datelen = term_strlen(p, meta->date);
 
 	p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
 	p->offset = 0;
@@ -987,7 +986,7 @@ print_man_foot(struct termp *p, const vo
 	if (p->offset + datelen >= p->rmargin)
 		p->rmargin = p->offset + datelen;
 
-	term_word(p, meta->date ? meta->date : "");
+	term_word(p, meta->date);
 	term_flushln(p);
 
 	p->flags &= ~TERMP_NOBREAK;
@@ -1024,8 +1023,7 @@ print_man_head(struct termp *p, const vo
 		strlcpy(buf, m->vol, BUFSIZ);
 	buflen = term_strlen(p, buf);
 
-	snprintf(title, BUFSIZ, "%s(%s)", m->title ? m->title : "",
-	    m->msec ? m->msec : "");
+	snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
 	titlen = term_strlen(p, title);
 
 	p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

  reply	other threads:[~2011-12-03 21:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <201111181639.pAIGd8Y3022061@krisdoz.my.domain>
2011-11-19 14:19 ` Ingo Schwarze
2011-11-20  4:25   ` Joerg Sonnenberger
2011-11-20  4:26     ` Joerg Sonnenberger
2011-11-20 12:27       ` Ingo Schwarze
2011-11-20 19:17         ` Joerg Sonnenberger
2011-12-03 21:41           ` Ingo Schwarze [this message]
2011-12-03 22:47             ` Joerg Sonnenberger
2011-12-03 23:50               ` Ingo Schwarze
2011-12-04  0:15                 ` Joerg Sonnenberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111203214157.GH17667@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).