From 124c3594cb65748ce858dcc55eadd7c831cee041 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 13 Mar 2016 20:21:00 +0200 Subject: Initial fix for use of closed end of two-way connection. --- builtin.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index c3a3bb22..784c8190 100644 --- a/builtin.c +++ b/builtin.c @@ -1664,8 +1664,12 @@ do_printf(int nargs, int redirtype) if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); rp = redirect(redir_exp, redirtype, & errflg); - if (rp != NULL) + if (rp != NULL) { + if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + fatal(_("printf: attempt to write to closed write end of two-way pipe")); + } fp = rp->output.fp; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else @@ -2136,8 +2140,12 @@ do_print(int nargs, int redirtype) if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); rp = redirect(redir_exp, redirtype, & errflg); - if (rp != NULL) + if (rp != NULL) { + if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + fatal(_("print: attempt to write to closed write end of two-way pipe")); + } fp = rp->output.fp; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else -- cgit v1.2.3 From 1662deffd0ced2464647ebff013be4d5ad398594 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 22 Mar 2016 07:53:46 +0200 Subject: Add fatal error for print if 2 way pipe write end closed. --- builtin.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 784c8190..c4d3d3a1 100644 --- a/builtin.c +++ b/builtin.c @@ -2208,8 +2208,12 @@ do_print_rec(int nargs, int redirtype) if (redirtype != 0) { redir_exp = TOP(); rp = redirect(redir_exp, redirtype, & errflg); - if (rp != NULL) + if (rp != NULL) { + if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + fatal(_("print: attempt to write to closed write end of two-way pipe")); + } fp = rp->output.fp; + } DEREF(redir_exp); decr_sp(); } else -- cgit v1.2.3 From 1b5d1b8870cb0ac1c4b99f6cf67e3277427df864 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 4 Apr 2016 23:11:19 +0300 Subject: Add warning for fflush of closed write end on 2-way pipe. --- builtin.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index c4d3d3a1..a1c09d5a 100644 --- a/builtin.c +++ b/builtin.c @@ -237,6 +237,9 @@ do_fflush(int nargs) fp = rp->output.fp; if (fp != NULL) status = rp->output.gawk_fflush(fp, rp->output.opaque); + else if ((rp->flag & RED_TWOWAY) != 0) + warning(_("fflush: cannot flush: two-way pipe `%s' has closed write end"), + file); } else if ((fp = stdfile(tmp->stptr, tmp->stlen)) != NULL) { status = fflush(fp); } else { -- cgit v1.2.3