summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-02-08 01:36:39 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-02-08 01:36:39 +0000
commit19a83488d0a029e5c126712b77dda1abadcb28e7 (patch)
tree419acaa00379da5d156e3da8ebe6cbcab52fc8ff /usr.bin
parenta810726c48edfdf6b49a44931898561d0df3f3a7 (diff)
Invalidate the tag_files.tfd after fclose(3)ing the stram associated with
it. In main assert that the tfd was actually invalidated. This avoids closing an invalid fd. ok deraadt on earlier version, tweak & ok schwarze
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/main.c4
-rw-r--r--usr.bin/mandoc/tag.c5
2 files changed, 6 insertions, 3 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 2c2377670fe..e7b875aec04 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.205 2017/08/21 15:41:26 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.206 2018/02/08 01:36:38 tb Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -1152,7 +1152,7 @@ spawn_pager(struct tag_files *tag_files)
if (dup2(tag_files->ofd, STDOUT_FILENO) == -1)
err((int)MANDOCLEVEL_SYSERR, "pager stdout");
close(tag_files->ofd);
- close(tag_files->tfd);
+ assert(tag_files->tfd == -1);
/* Do not start the pager before controlling the terminal. */
diff --git a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c
index bcf1a55fdd6..9c9674be9d7 100644
--- a/usr.bin/mandoc/tag.c
+++ b/usr.bin/mandoc/tag.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tag.c,v 1.18 2017/02/09 17:19:07 schwarze Exp $ */
+/* $OpenBSD: tag.c,v 1.19 2018/02/08 01:36:38 tb Exp $ */
/*
* Copyright (c) 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -211,6 +211,9 @@ tag_write(void)
ohash_delete(&tag_data);
if (stream != NULL)
fclose(stream);
+ else
+ close(tag_files.tfd);
+ tag_files.tfd = -1;
}
void