source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Jumping out of man_unscope() for the root node is a bad idea
@ 2011-12-04  0:44 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2011-12-04  0:44 UTC (permalink / raw)
  To: source

Log Message:
-----------
Jumping out of man_unscope() for the root node is a bad idea
because that will skip root node validation, potentially entering
rendering modules will NULL pointers lurking in the meta data.
Instead, always validate the root node and (as suggested by joerg@)
assert validity of the meta data before using it in the renderers.
ok joerg@

Modified Files:
--------------
    mdocml:
        man_html.c
        man_macro.c
        man_term.c

Revision Data
-------------
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.124
retrieving revision 1.125
diff -Lman_term.c -Lman_term.c -u -p -r1.124 -r1.125
--- man_term.c
+++ man_term.c
@@ -963,15 +963,17 @@ print_man_foot(struct termp *p, const vo
 	const struct man_meta *meta;
 
 	meta = (const struct man_meta *)arg;
+	assert(meta->title);
+	assert(meta->msec);
+	assert(meta->date);
 
 	term_fontrepl(p, TERMFONT_NONE);
 
 	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 +989,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;
@@ -1008,6 +1010,8 @@ print_man_head(struct termp *p, const vo
 	const struct man_meta *m;
 
 	m = (const struct man_meta *)arg;
+	assert(m->title);
+	assert(m->msec);
 
 	/*
 	 * Note that old groff would spit out some spaces before the
@@ -1024,8 +1028,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;
Index: man_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_html.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -Lman_html.c -Lman_html.c -u -p -r1.84 -r1.85
--- man_html.c
+++ man_html.c
@@ -178,6 +178,8 @@ print_man_head(MAN_ARGS)
 {
 
 	print_gen_head(h);
+	assert(m->title);
+	assert(m->msec);
 	bufcat_fmt(h, "%s(%s)", m->title, m->msec);
 	print_otag(h, TAG_TITLE, 0, NULL);
 	print_text(h, h->buf);
@@ -305,8 +307,9 @@ 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 : "");
+	assert(m->title);
+	assert(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 +363,8 @@ 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);
+	assert(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
retrieving revision 1.70
diff -Lman_macro.c -Lman_macro.c -u -p -r1.69 -r1.70
--- man_macro.c
+++ man_macro.c
@@ -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 */
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-12-04  0:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-04  0:44 mdocml: Jumping out of man_unscope() for the root node is a bad idea schwarze

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).