From a25aeda82389fca9c3643207514c8bd78d173ab2 Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 24 Sep 2025 21:27:21 +0000 Subject: [PATCH] Fix a bug where formatting two compressed manual pages in row failed to decompress the second one. The problem was calling mparse*() functions in the wrong order mparse_open -> mparse_reset -> mparse_readfd instead of in the correct order mparse_reset -> mparse_open -> mparse_readfd: mparse_reset() clears the gzip flag, mparse_open() sets it if the new file is gzipped, and read_whole_file() called from mparse_readfd() enables decompression if the flag is set. To make the code easier to follow, call all of mparse_alloc(), mparse_reset(), and mparse_free() from main() rather than hiding mparse_reset() two levels down in the parse() subroutine. Bug found by Alejandro Colomar on Debian Sid and reported on the GNU roff mailing list. --- usr.bin/mandoc/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 56f8c422177..01c1d7aa3f9 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,6 +1,6 @@ -/* $OpenBSD: main.c,v 1.266 2025/08/28 16:37:25 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.267 2025/09/24 21:27:21 schwarze Exp $ */ /* - * Copyright (c) 2010-2012, 2014-2021 Ingo Schwarze + * Copyright (c) 2010-2012,2014-2021,2025 Ingo Schwarze * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010 Joerg Sonnenberger * @@ -579,6 +579,8 @@ main(int argc, char *argv[]) mp = mparse_alloc(options, os_e, os_s); for (i = 0; i < ressz; i++) { + if (i > 0) + mparse_reset(mp); process_onefile(mp, res + i, &outst, &conf); if (outst.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK) break; @@ -894,18 +896,12 @@ parse(struct mparse *mp, int fd, const char *file, struct outstate *outst, struct manconf *conf) { static struct manpaths basepaths; - static int previous; struct roff_meta *meta; assert(fd >= 0); if (file == NULL) file = ""; - if (previous) - mparse_reset(mp); - else - previous = 1; - mparse_readfd(mp, fd, file); if (fd != STDIN_FILENO) close(fd);