From e0775496049b1f1c4aa21434142ccda12eb3146b Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 19 Nov 2012 22:30:58 +0000 Subject: Do not crash on stray .Ta macros found outside column lists. Problem reported by jmc@, thanks. --- TODO | 8 ++------ mandoc.h | 4 +++- mdoc_macro.c | 16 +++++++++++----- read.c | 5 +++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index 01a92848..d369bd0a 100644 --- a/TODO +++ b/TODO @@ -1,17 +1,13 @@ ************************************************************************ * Official mandoc TODO. -* $Id: TODO,v 1.147 2012/11/18 00:05:35 schwarze Exp $ +* $Id: TODO,v 1.148 2012/11/19 22:30:58 schwarze Exp $ ************************************************************************ ************************************************************************ * crashes ************************************************************************ -- $ echo ".Ta" >> ls.1 - $ mandoc ls.1 - assertion "MDOC_BLOCK == p->parent->type" failed: - file "/usr/src/usr.bin/mandoc/mdoc.c", line 399, function "node_append" - from jmc@ Thu, 20 Sep 2012 21:35:58 +0059 +None known right now. ************************************************************************ * missing features diff --git a/mandoc.h b/mandoc.h index 1f072963..f84b746c 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,6 +1,7 @@ -/* $Id: mandoc.h,v 1.105 2012/11/16 22:21:05 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.106 2012/11/19 22:30:58 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons + * Copyright (c) 2012 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -135,6 +136,7 @@ enum mandocerr { MANDOCERR_MACRO, /* skipping unknown macro */ MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */ MANDOCERR_ARGCOUNT, /* argument count wrong */ + MANDOCERR_STRAYTA, /* skipping column outside column list */ MANDOCERR_NOSCOPE, /* skipping end of block that is not open */ MANDOCERR_SCOPEBROKEN, /* missing end of block */ MANDOCERR_SCOPEEXIT, /* scope open on exit */ diff --git a/mdoc_macro.c b/mdoc_macro.c index 1cec1ecd..7e143e02 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.120 2012/11/18 00:05:35 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.121 2012/11/19 22:30:58 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2012 Ingo Schwarze @@ -1759,16 +1759,22 @@ phrase(struct mdoc *mdoc, int line, int ppos, char *buf) static int phrase_ta(MACRO_PROT_ARGS) { + struct mdoc_node *n; int la; enum mdoct ntok; enum margserr ac; char *p; - /* - * FIXME: this is overly restrictive: if the `Ta' is unexpected, - * it should simply error out with ARGSLOST. - */ + /* Make sure we are in a column list or ignore this macro. */ + n = mdoc->last; + while (NULL != n && MDOC_Bl != n->tok) + n = n->parent; + if (NULL == n || LIST_column != n->norm->Bl.type) { + mdoc_pmsg(mdoc, line, ppos, MANDOCERR_STRAYTA); + return(1); + } + /* Advance to the next column. */ if ( ! rew_sub(MDOC_BODY, mdoc, MDOC_It, line, ppos)) return(0); if ( ! mdoc_body_alloc(mdoc, line, ppos, MDOC_It)) diff --git a/read.c b/read.c index 89b2c28d..cf780626 100644 --- a/read.c +++ b/read.c @@ -1,7 +1,7 @@ -/* $Id: read.c,v 1.33 2012/11/19 17:57:23 schwarze Exp $ */ +/* $Id: read.c,v 1.34 2012/11/19 22:30:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2011 Ingo Schwarze + * Copyright (c) 2010, 2011, 2012 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -180,6 +180,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "skipping unknown macro", "NOT IMPLEMENTED, please use groff: skipping request", "argument count wrong", + "skipping column outside column list", "skipping end of block that is not open", "missing end of block", "scope open on exit", -- cgit v1.2.3-56-ge451