From 79d7c51d638887c3eb7157f2be65ebaab49fe34c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 20 Jul 2020 18:55:16 +0000 Subject: In closeall(), skip stdin and flush std{err,out} instead of closing. Otherwise awk could fclose(stdin) twice (it may appear more than once) and closing stderr means awk cannot report errors closing other streams. OK tim@ --- usr.bin/awk/run.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 4ba6c79eac1..a826182672e 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.63 2020/07/02 19:06:22 millert Exp $ */ +/* $OpenBSD: run.c,v 1.64 2020/07/20 18:55:15 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -1977,8 +1977,12 @@ void closeall(void) continue; if (ferror(files[i].fp)) FATAL( "i/o error occurred on %s", files[i].fname ); + if (files[i].fp == stdin) + continue; if (files[i].mode == '|' || files[i].mode == LE) stat = pclose(files[i].fp) == -1; + else if (files[i].fp == stdout || files[i].fp == stderr) + stat = fflush(files[i].fp) == EOF; else stat = fclose(files[i].fp) == EOF; if (stat) -- cgit v1.2.3