Skip to content

Commit

Permalink
expand: Fix here-document file descriptor leak
Browse files Browse the repository at this point in the history
Swap the order of here-document expansion and pipe creation as
otherwise the pipe file descriptors will become accessible in the
expanded text.

Fixes: f4ee8c8 ("[EXPAND] Expand here-documents in the...")
Signed-off-by: Herbert Xu <[email protected]>
(cherry picked from commit 21847204559bf9a720f3863e19e8f046fdce0bf1)
  • Loading branch information
herbertx authored and hvdijk committed Apr 25, 2024
1 parent 7af25cd commit 06fdaa4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,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);
Expand Down

0 comments on commit 06fdaa4

Please sign in to comment.