From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Delete the redundant tbl span flags, just inspect the actual
Date: Fri, 30 Jan 2015 12:32:46 -0500 (EST) [thread overview]
Message-ID: <1504504056425674909.enqueue@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2015-01-30 17:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1504504056425674909.enqueue@fantadrom.bsd.lv \
--to=schwarze@mdocml.bsd.lv \
--cc=source@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).