From 658ede8ca657fe56c7ea6b0a3a1bd89fb858d26d Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 7 Apr 2016 21:46:44 +0300 Subject: Fix race condition in fatal errors for one end closed on two way pipe. --- io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index fe1261aa..3a5748b2 100644 --- a/io.c +++ b/io.c @@ -212,8 +212,6 @@ #define INCREMENT_REC(X) X++ #endif -typedef enum { CLOSE_ALL, CLOSE_TO, CLOSE_FROM } two_way_close_type; - /* Several macros to make the code a bit clearer. */ #define at_eof(iop) (((iop)->flag & IOP_AT_EOF) != 0) #define has_no_data(iop) ((iop)->dataend == NULL) @@ -1170,7 +1168,7 @@ do_close(int nargs) /* close_rp --- separate function to just do closing */ -static int +int close_rp(struct redirect *rp, two_way_close_type how) { int status = 0; @@ -2475,6 +2473,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) } return make_number((AWKNUM) -1.0); } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) { + (void) close_rp(rp, CLOSE_ALL); fatal(_("getline: attempt to read from closed read end of two-way pipe")); } iop = rp->iop; -- cgit v1.2.3