summaryrefslogtreecommitdiff
path: root/usr.bin/awk
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2020-07-20 18:57:20 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2020-07-20 18:57:20 +0000
commit9f82ebd77a4718260beec1aaa6b401125d492555 (patch)
tree67da7f29a88f4fbe83918bb82656a10252a504cf /usr.bin/awk
parent79d7c51d638887c3eb7157f2be65ebaab49fe34c (diff)
If closefile() is called on std{in,out,err}, freopen() /dev/null instead.
Otherwise, awk will continue trying to perform I/O on a closed stdio stream. This appears to be consistent with how gawk behaves. OK tim@
Diffstat (limited to 'usr.bin/awk')
-rw-r--r--usr.bin/awk/run.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c
index a826182672e..357a79ccb71 100644
--- a/usr.bin/awk/run.c
+++ b/usr.bin/awk/run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: run.c,v 1.64 2020/07/20 18:55:15 millert Exp $ */
+/* $OpenBSD: run.c,v 1.65 2020/07/20 18:57:19 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -1950,7 +1950,10 @@ const char *filename(FILE *fp)
continue;
if (ferror(files[i].fp))
FATAL("i/o error occurred on %s", files[i].fname);
- if (files[i].mode == '|' || files[i].mode == LE)
+ if (files[i].fp == stdin || files[i].fp == stdout ||
+ files[i].fp == stderr)
+ stat = freopen("/dev/null", "r+", files[i].fp) == NULL;
+ else if (files[i].mode == '|' || files[i].mode == LE)
stat = pclose(files[i].fp) == -1;
else
stat = fclose(files[i].fp) == EOF;
@@ -1960,6 +1963,7 @@ const char *filename(FILE *fp)
xfree(files[i].fname);
files[i].fname = NULL; /* watch out for ref thru this */
files[i].fp = NULL;
+ break;
}
tempfree(x);
x = gettemp();