From c96b4f2bf87e619a2f29a265defd0972c17bff04 Mon Sep 17 00:00:00 2001 From: schwarze Date: Sun, 4 Jul 2021 15:38:08 +0000 Subject: [PATCH] The mandoc(1) manual already mentions that -T man output mode neither supports tbl(7) nor eqn(7) input. If an input file contains such code anyway, tell the user rather than failing an assert(3)ion. Fixing a crash reported by Bjarni Ingi Gislason in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901636 which the Debian maintainer of mandoc, Michael at Stapelberg dot ch, forwarded to me. --- usr.bin/mandoc/mandoc.1 | 24 ++++++++++++++++++++++-- usr.bin/mandoc/mandoc.h | 6 ++++-- usr.bin/mandoc/mandoc_msg.c | 6 ++++-- usr.bin/mandoc/mdoc_man.c | 34 +++++++++++++++++++++++----------- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 519b065648d..6df390cce3c 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.177 2021/06/28 19:49:57 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.178 2021/07/04 15:38:08 schwarze Exp $ .\" .\" Copyright (c) 2012, 2014-2021 Ingo Schwarze .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 28 2021 $ +.Dd $Mdocdate: July 4 2021 $ .Dt MANDOC 1 .Os .Sh NAME @@ -2314,6 +2314,26 @@ or macro or of an undefined macro. The macro is ignored, and its arguments are handled as if they were a text line. +.It Sy "skipping tbl in -Tman mode" +.Pq mdoc , tbl +An input file contains the +.Ic \&TS +macro. +This message is only generated in +.Fl T Cm man +output mode, where +.Xr tbl 7 +input is not supported. +.It Sy "skipping eqn in -Tman mode" +.Pq mdoc , eqn +An input file contains the +.Ic \&EQ +macro. +This message is only generated in +.Fl T Cm man +output mode, where +.Xr eqn 7 +input is not supported. .El .Ss Bad command line arguments .Bl -ohang diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 0bd681cba91..1aef8c2d69d 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,6 +1,6 @@ -/* $OpenBSD: mandoc.h,v 1.213 2021/06/27 17:57:13 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.214 2021/07/04 15:38:08 schwarze Exp $ */ /* - * Copyright (c) 2012-2020 Ingo Schwarze + * Copyright (c) 2012-2021 Ingo Schwarze * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any @@ -245,6 +245,8 @@ enum mandocerr { MANDOCERR_TBLOPT_EQN, /* eqn delim option in tbl: arg */ MANDOCERR_TBLLAYOUT_MOD, /* unsupported tbl layout modifier: m */ MANDOCERR_TBLMACRO, /* ignoring macro in table: macro */ + MANDOCERR_TBL_TMAN, /* skipping tbl in -Tman mode */ + MANDOCERR_EQN_TMAN, /* skipping eqn in -Tman mode */ MANDOCERR_BADARG, /* ===== start of bad invocations ===== */ diff --git a/usr.bin/mandoc/mandoc_msg.c b/usr.bin/mandoc/mandoc_msg.c index 1d20cfc1bf2..26306dad7e9 100644 --- a/usr.bin/mandoc/mandoc_msg.c +++ b/usr.bin/mandoc/mandoc_msg.c @@ -1,6 +1,6 @@ -/* $OpenBSD: mandoc_msg.c,v 1.12 2021/06/27 17:57:13 schwarze Exp $ */ +/* $OpenBSD: mandoc_msg.c,v 1.13 2021/07/04 15:38:09 schwarze Exp $ */ /* - * Copyright (c) 2014-2020 Ingo Schwarze + * Copyright (c) 2014-2021 Ingo Schwarze * Copyright (c) 2010, 2011 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any @@ -243,6 +243,8 @@ static const char *const type_message[MANDOCERR_MAX] = { "eqn delim option in tbl", "unsupported tbl layout modifier", "ignoring macro in table", + "skipping tbl in -Tman mode", + "skipping eqn in -Tman mode", /* bad command line arguments */ NULL, diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 25d59a5a01b..a2baf55a62a 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,6 +1,6 @@ -/* $OpenBSD: mdoc_man.c,v 1.134 2020/02/27 01:25:57 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.135 2021/07/04 15:38:09 schwarze Exp $ */ /* - * Copyright (c) 2011-2020 Ingo Schwarze + * Copyright (c) 2011-2021 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 @@ -658,7 +658,20 @@ print_node(DECL_ARGS) do_sub = 1; n->flags &= ~NODE_ENDED; - if (n->type == ROFFT_TEXT) { + switch (n->type) { + case ROFFT_EQN: + case ROFFT_TBL: + mandoc_msg(n->type == ROFFT_EQN ? MANDOCERR_EQN_TMAN : + MANDOCERR_TBL_TMAN, n->line, n->pos, NULL); + outflags |= MMAN_PP | MMAN_sp | MMAN_nl; + print_word("The"); + print_line(".B \\-T man", MMAN_nl); + print_word("output mode does not support"); + print_word(n->type == ROFFT_EQN ? "eqn(7)" : "tbl(7)"); + print_word("input."); + outflags |= MMAN_PP | MMAN_sp | MMAN_nl; + return; + case ROFFT_TEXT: /* * Make sure that we don't happen to start with a * control character at the start of a line. @@ -678,19 +691,18 @@ print_node(DECL_ARGS) outflags &= ~(MMAN_spc | MMAN_spc_force); else if (outflags & MMAN_Sm) outflags |= MMAN_spc; - } else if (n->tok < ROFF_MAX) { - (*roff_man_acts[n->tok])(meta, n); - return; - } else { - /* - * Conditionally run the pre-node action handler for a - * node. - */ + break; + default: + if (n->tok < ROFF_MAX) { + (*roff_man_acts[n->tok])(meta, n); + return; + } act = mdoc_man_act(n->tok); cond = act->cond == NULL || (*act->cond)(meta, n); if (cond && act->pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) do_sub = (*act->pre)(meta, n); + break; } /* -- 2.20.1