summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2020-07-20 18:57:19 +0000
committermillert <millert@openbsd.org>2020-07-20 18:57:19 +0000
commit95944651e29b62c80a936087f6ffcdf305d5c643 (patch)
tree9d577b1ab968f9a7e0193e6c1e5e24a5510cdee6 /usr.bin
parentIn closeall(), skip stdin and flush std{err,out} instead of closing. (diff)
downloadwireguard-openbsd-95944651e29b62c80a936087f6ffcdf305d5c643.tar.xz
wireguard-openbsd-95944651e29b62c80a936087f6ffcdf305d5c643.zip
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')
-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();