DASH Shell discussions
 help / color / mirror / Atom feed
* [PATCH] expand: Fix here-document file descriptor leak
@ 2024-04-14  3:08 Herbert Xu
  0 siblings, 0 replies; only message in thread
From: Herbert Xu @ 2024-04-14  3:08 UTC (permalink / raw)
  To: dash

Swap the order of here-document expansion and pipe creation as
otherwise the pipe file descriptors will become accessible in the
expanded text.

Fixes: f4ee8c859c3d ("[EXPAND] Expand here-documents in the...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/redir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/redir.c b/src/redir.c
index d74602c..bcc81b4 100644
--- a/src/redir.c
+++ b/src/redir.c
@@ -335,15 +335,15 @@ openhere(union node *redir)
 	int pip[2];
 	size_t len = 0;
 
-	if (pipe(pip) < 0)
-		sh_error("Pipe call failed");
-
 	p = redir->nhere.doc->narg.text;
 	if (redir->type == NXHERE) {
 		expandarg(redir->nhere.doc, NULL, EXP_QUOTED);
 		p = stackblock();
 	}
 
+	if (pipe(pip) < 0)
+		sh_error("Pipe call failed");
+
 	len = strlen(p);
 	if (len <= PIPESIZE) {
 		xwrite(pip[1], p, len);
-- 
2.39.2

-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-14  3:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-14  3:08 [PATCH] expand: Fix here-document file descriptor leak Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox