projects
/
musl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8253f59
)
fix fd leak and case where fd 1 is already closed in wordexp
author
Rich Felker
<dalias@aerifal.cx>
Fri, 22 Nov 2013 20:55:58 +0000
(15:55 -0500)
committer
Rich Felker
<dalias@aerifal.cx>
Fri, 22 Nov 2013 20:55:58 +0000
(15:55 -0500)
src/misc/wordexp.c
patch
|
blob
|
history
diff --git
a/src/misc/wordexp.c
b/src/misc/wordexp.c
index
8f0d42f
..
1387b5d
100644
(file)
--- a/
src/misc/wordexp.c
+++ b/
src/misc/wordexp.c
@@
-8,6
+8,7
@@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
+#include <fcntl.h>
#include "pthread_impl.h"
static char *getword(FILE *f)
#include "pthread_impl.h"
static char *getword(FILE *f)
@@
-88,7
+89,7
@@
static int do_wordexp(const char *s, wordexp_t *we, int flags)
we->we_offs = 0;
}
we->we_offs = 0;
}
- if (pipe
(p
) < 0) goto nospace;
+ if (pipe
2(p, O_CLOEXEC
) < 0) goto nospace;
__block_all_sigs(&set);
pid = fork();
__restore_sigs(&set);
__block_all_sigs(&set);
pid = fork();
__restore_sigs(&set);
@@
-98,9
+99,8
@@
static int do_wordexp(const char *s, wordexp_t *we, int flags)
goto nospace;
}
if (!pid) {
goto nospace;
}
if (!pid) {
- dup2(p[1], 1);
- close(p[0]);
- close(p[1]);
+ if (p[1] == 1) fcntl(1, F_SETFD, 0);
+ else dup2(p[1], 1);
execl("/bin/sh", "sh", "-c",
"eval \"printf %s\\\\\\\\0 x $1 $2\"",
"sh", s, redir, (char *)0);
execl("/bin/sh", "sh", "-c",
"eval \"printf %s\\\\\\\\0 x $1 $2\"",
"sh", s, redir, (char *)0);