From e61ed2b80d60ca095006d7512f90c07e6c572ee0 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 29 Sep 2016 11:16:24 -0700 Subject: 39470: failure to open a supposedly unique temp file name should result in an error Also band-aid for signal-related race conditions in temp file name generation --- Src/exec.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'Src/exec.c') diff --git a/Src/exec.c b/Src/exec.c index e3915ddfe..04868bd37 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4412,11 +4412,17 @@ getoutputfile(char *cmd, char **eptr) untokenize(s); } - addfilelist(nam, 0); + if (!s) /* Unclear why we need to do this before open() */ + child_block(); /* but it has been so for a long time: leave it */ - if (!s) - child_block(); - fd = open(nam, O_WRONLY | O_CREAT | O_EXCL | O_NOCTTY, 0600); + if ((fd = open(nam, O_WRONLY | O_CREAT | O_EXCL | O_NOCTTY, 0600)) < 0) { + zerr("process substitution failed: %e", errno); + free(nam); + if (!s) + child_unblock(); + return NULL; + } + addfilelist(nam, 0); if (s) { /* optimised here-string */ @@ -4427,7 +4433,7 @@ getoutputfile(char *cmd, char **eptr) return nam; } - if (fd < 0 || (cmdoutpid = pid = zfork(NULL)) == -1) { + if ((cmdoutpid = pid = zfork(NULL)) == -1) { /* fork or open error */ child_unblock(); return nam; -- cgit 1.4.1