[PATCH] expand: Fix here-document file descriptor leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux