diff options
author | jilles <jilles@FreeBSD.org> | 2014-03-26 20:43:40 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2014-03-26 20:43:40 +0000 |
commit | 270892ce0aa34981474cedfa90e120b5971c6e13 (patch) | |
tree | fbddad8551c3a2e6b6992b43332553c88006070a /bin/sh/redir.c | |
parent | 6ceec4444ddbcea29246cb67b83eff062485cdc3 (diff) | |
download | FreeBSD-src-270892ce0aa34981474cedfa90e120b5971c6e13.zip FreeBSD-src-270892ce0aa34981474cedfa90e120b5971c6e13.tar.gz |
sh: Fix possible memory leaks and double frees with unexpected SIGINT.
Diffstat (limited to 'bin/sh/redir.c')
-rw-r--r-- | bin/sh/redir.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/bin/sh/redir.c b/bin/sh/redir.c index 647b10a..6127e86 100644 --- a/bin/sh/redir.c +++ b/bin/sh/redir.c @@ -92,6 +92,13 @@ static int openhere(union node *); * undone by calling popredir. If the REDIR_BACKQ flag is set, then the * standard output, and the standard error if it becomes a duplicate of * stdout, is saved in memory. +* + * We suppress interrupts so that we won't leave open file + * descriptors around. Because the signal handler remains + * installed and we do not use system call restart, interrupts + * will still abort blocking opens such as fifos (they will fail + * with EINTR). There is, however, a race condition if an interrupt + * arrives after INTOFF and before open blocks. */ void @@ -103,6 +110,7 @@ redirect(union node *redir, int flags) int fd; char memory[10]; /* file descriptors to write to memory */ + INTOFF; for (i = 10 ; --i >= 0 ; ) memory[i] = 0; memory[1] = flags & REDIR_BACKQ; @@ -139,11 +147,14 @@ redirect(union node *redir, int flags) INTON; } openredirect(n, memory); + INTON; + INTOFF; } if (memory[1]) out1 = &memout; if (memory[2]) out2 = &memout; + INTON; } @@ -156,15 +167,6 @@ openredirect(union node *redir, char memory[10]) int f; int e; - /* - * We suppress interrupts so that we won't leave open file - * descriptors around. Because the signal handler remains - * installed and we do not use system call restart, interrupts - * will still abort blocking opens such as fifos (they will fail - * with EINTR). There is, however, a race condition if an interrupt - * arrives after INTOFF and before open blocks. - */ - INTOFF; memory[fd] = 0; switch (redir->nfile.type) { case NFROM: @@ -237,7 +239,6 @@ movefd: default: abort(); } - INTON; } |