From 997eafdcad85e9a2c59db1141b404dd4c4bcb22d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 21 Sep 2009 20:49:21 +0000 Subject: 27283: failure to dup fd caused mayhem --- ChangeLog | 7 ++++++- Src/exec.c | 1 + Src/utils.c | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a477ad8a..9e9e6d89a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-09-21 Peter Stephenson + + * 27283: Src/exec.c, Src/utils.c: failure to dup fd accessed + uninitialised memory and closed the original fd regardless. + 2009-09-21 Peter Stephenson * users/14411: Src/hashtable.c: only hash stat-able executable @@ -12197,5 +12202,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.4784 $ +* $Revision: 1.4785 $ ***************************************************** diff --git a/Src/exec.c b/Src/exec.c index e68237948..ca9cf0f4d 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1980,6 +1980,7 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag, */ if (fdN < 0 && errno != EBADF) { zerr("cannot duplicate fd %d: %e", fd1, errno); + mfds[fd1] = NULL; closemnodes(mfds); return; } diff --git a/Src/utils.c b/Src/utils.c index ad4ffca92..a12914787 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1631,7 +1631,8 @@ movefd(int fd) #else int fe = movefd(dup(fd)); #endif - zclose(fd); + if (fe != -1) + zclose(fd); fd = fe; } if(fd != -1) { -- cgit 1.4.1