source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Delete the redundant tbl span flags, just inspect the actual
@ 2015-01-30 17:32 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-01-30 17:32 UTC (permalink / raw)
  To: source

Log Message:
-----------
Delete the redundant tbl span flags, just inspect the actual data
where needed, which is less fragile.  
This fixes a subtle NULL pointer access to tp->tbl.cols: 
Due to a bug in the man(7) parser, the first span of a table can
end up in a .TP head, in which case tblcalc() was never called.
Found by jsg@ with afl.

Modified Files:
--------------
    mdocml:
        man_term.c
        mandoc.h
        tbl.c
        tbl_data.c
        tbl_html.c
        tbl_term.c

Revision Data
-------------
Index: tbl_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_term.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.36 -r1.37
--- tbl_term.c
+++ tbl_term.c
@@ -81,7 +81,7 @@ term_tbl(struct termp *tp, const struct 
 	 * calculate the table widths and decimal positions.
 	 */
 
-	if (sp->flags & TBL_SPAN_FIRST) {
+	if (tp->tbl.cols == NULL) {
 		term_flushln(tp);
 
 		tp->tbl.len = term_tbl_len;
@@ -189,7 +189,7 @@ term_tbl(struct termp *tp, const struct 
 	 * existing table configuration and set it to NULL.
 	 */
 
-	if (sp->flags & TBL_SPAN_LAST) {
+	if (sp->next == NULL) {
 		if (sp->opts->opts & (TBL_OPT_DBOX | TBL_OPT_BOX)) {
 			tbl_hrule(tp, sp, 1);
 			tp->skipvsp = 1;
Index: man_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_term.c,v
retrieving revision 1.166
retrieving revision 1.167
diff -Lman_term.c -Lman_term.c -u -p -r1.166 -r1.167
--- man_term.c
+++ man_term.c
@@ -949,7 +949,7 @@ print_man_node(DECL_ARGS)
 		 * Tables are preceded by a newline.  Then process a
 		 * table line, which will cause line termination,
 		 */
-		if (TBL_SPAN_FIRST & n->span->flags)
+		if (n->span->prev == NULL)
 			term_newln(p);
 		term_tbl(p, n->span);
 		return;
Index: tbl_data.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_data.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -Ltbl_data.c -Ltbl_data.c -u -p -r1.38 -r1.39
--- tbl_data.c
+++ tbl_data.c
@@ -173,7 +173,6 @@ newspan(struct tbl_node *tbl, int line, 
 	if (dp->prev == NULL) {
 		tbl->first_span = dp;
 		tbl->current_span = NULL;
-		dp->flags |= TBL_SPAN_FIRST;
 	} else
 		dp->prev->next = dp;
 	tbl->last_span = dp;
Index: tbl_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_html.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -Ltbl_html.c -Ltbl_html.c -u -p -r1.15 -r1.16
--- tbl_html.c
+++ tbl_html.c
@@ -54,7 +54,7 @@ html_tblopen(struct html *h, const struc
 	struct roffcol	*col;
 	int		 ic;
 
-	if (sp->flags & TBL_SPAN_FIRST) {
+	if (h->tbl.cols == NULL) {
 		h->tbl.len = html_tbl_len;
 		h->tbl.slen = html_tbl_strlen;
 		tblcalc(&h->tbl, sp, 0);
@@ -132,7 +132,7 @@ print_tbl(struct html *h, const struct t
 
 	h->flags &= ~HTML_NONOSPACE;
 
-	if (sp->flags & TBL_SPAN_LAST) {
+	if (sp->next == NULL) {
 		assert(h->tbl.cols);
 		free(h->tbl.cols);
 		h->tbl.cols = NULL;
Index: tbl.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -Ltbl.c -Ltbl.c -u -p -r1.38 -r1.39
--- tbl.c
+++ tbl.c
@@ -179,9 +179,5 @@ tbl_end(struct tbl_node **tblp)
 		    tbl->line, tbl->pos, NULL);
 		return(0);
 	}
-
-	if (tbl->last_span != NULL)
-		tbl->last_span->flags |= TBL_SPAN_LAST;
-
 	return(1);
 }
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.h,v
retrieving revision 1.193
retrieving revision 1.194
diff -Lmandoc.h -Lmandoc.h -u -p -r1.193 -r1.194
--- mandoc.h
+++ mandoc.h
@@ -285,9 +285,6 @@ struct	tbl_span {
 	struct tbl_span	 *prev;
 	struct tbl_span	 *next;
 	int		  line; /* parse line */
-	int		  flags;
-#define	TBL_SPAN_FIRST	 (1 << 0)
-#define	TBL_SPAN_LAST	 (1 << 1)
 	enum tbl_spant	  pos;
 };
 
--
 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:[~2015-01-30 17:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-30 17:32 mdocml: Delete the redundant tbl span flags, just inspect the actual 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).