aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--builtin.c12
-rw-r--r--io.c2
2 files changed, 12 insertions, 2 deletions
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
diff --git a/io.c b/io.c
index d4435684..de753973 100644
--- a/io.c
+++ b/io.c
@@ -2473,6 +2473,8 @@ do_getline_redir(int into_variable, enum redirval redirtype)
update_ERRNO_int(redir_error);
}
return make_number((AWKNUM) -1.0);
+ } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) {
+ fatal(_("getline: attempt to read from closed read end of two-way pipe"));
}
iop = rp->iop;
if (iop == NULL) /* end of input */