Message ID | ZhtIkl3b3GhYVqAJ@gondor.apana.org.au (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Herbert Xu |
Headers | show |
Series | expand: Fix here-document file descriptor leak | expand |
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);
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(-)