diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-21 17:15:18 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-21 17:15:18 +0000 |
commit | a90a19d8ea1fd9c75174c833a56f4c68dae450c4 (patch) | |
tree | 6040fbeff2ceb01c795fcdc0bf917f24038e4b44 /man_macro.c | |
parent | 3cfd064738dd1ac7b31bfbb5b6eab47b4ea99b2c (diff) | |
download | mandoc-a90a19d8ea1fd9c75174c833a56f4c68dae450c4.tar.gz mandoc-a90a19d8ea1fd9c75174c833a56f4c68dae450c4.tar.zst mandoc-a90a19d8ea1fd9c75174c833a56f4c68dae450c4.zip |
Rename mandoc_getarg() to roff_getarg() and pass it the roff parser
struct as an argument such that after copy-in, it can call roff_expand()
once again, which used to be called roff_res() before this. This
fixes a subtle low-level roff(7) parsing bug reported by Fabio
Scotoni <fabio at esse dot ch> in the 4.4BSD-Lite2 mdoc.samples(7)
manual page, because that page used an escaped escape sequence in
a macro argument.
To expand escaped escape sequences in quoted mdoc(7) arguments, too,
stop bypassing the call to roff_getarg() in mdoc_argv.c, function args()
for this case. This does not solve the case of escaped escape sequences
in quoted .Bl -column phrases yet.
Because roff_expand() can make the string longer, roff_getarg() can no
longer operate in-place but needs to malloc(3) the returned string.
In the high-level parsers, free(3) that string after processing it.
Diffstat (limited to 'man_macro.c')
-rw-r--r-- | man_macro.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/man_macro.c b/man_macro.c index faa37bf9..63ffc131 100644 --- a/man_macro.c +++ b/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.136 2018/12/14 06:33:14 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.137 2018/12/21 17:15:18 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2012-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> @@ -202,22 +202,25 @@ blk_close(MACRO_PROT_ARGS) { enum roff_tok ctok, ntok; const struct roff_node *nn; - char *p; - int cline, cpos, nrew, target; + char *p, *ep; + int cline, cpos, la, nrew, target; nrew = 1; switch (tok) { case MAN_RE: ntok = MAN_RS; + la = *pos; if ( ! man_args(man, line, pos, buf, &p)) break; for (nn = man->last->parent; nn; nn = nn->parent) if (nn->tok == ntok && nn->type == ROFFT_BLOCK) nrew++; - target = strtol(p, &p, 10); - if (*p != '\0') + target = strtol(p, &ep, 10); + if (*ep != '\0') mandoc_msg(MANDOCERR_ARG_EXCESS, line, - (int)(p - buf), "RE ... %s", p); + la + (buf[la] == '"') + (int)(ep - p), + "RE ... %s", ep); + free(p); if (target == 0) target = 1; nrew -= target; @@ -312,6 +315,7 @@ blk_exp(MACRO_PROT_ARGS) roff_setreg(man->roff, "an-margin", head->aux, '+'); } + free(p); } if (buf[*pos] != '\0') @@ -348,6 +352,7 @@ blk_imp(MACRO_PROT_ARGS) if ( ! man_args(man, line, pos, buf, &p)) break; roff_word_alloc(man, line, la, p); + free(p); } /* @@ -397,6 +402,7 @@ in_line_eoln(MACRO_PROT_ARGS) roff_word_append(man, p); else roff_word_alloc(man, line, la, p); + free(p); } /* @@ -456,6 +462,6 @@ man_args(struct roff_man *man, int line, int *pos, char *buf, char **v) if ('\0' == *start) return 0; - *v = mandoc_getarg(v, line, pos); + *v = roff_getarg(man->roff, v, line, pos); return 1; } |