summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-06 21:48:16 +0200
committerAustin Foxley <austinf@cetoncorp.com>2009-09-18 11:41:35 -0700
commita6503dd658b0a0d6fc6fe3cca9e6641e47399164 (patch)
treef457cfdc82dc4c5a8e3f73f3c593dfe0fe479e01
parentec684d6572952195494d779bdb90c467e9449a66 (diff)
downloaduClibc-alpine-a6503dd658b0a0d6fc6fe3cca9e6641e47399164.tar.bz2
uClibc-alpine-a6503dd658b0a0d6fc6fe3cca9e6641e47399164.tar.xz
wordexp.c: fix a bug where we might close stdout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
-rw-r--r--libc/misc/wordexp/wordexp.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/libc/misc/wordexp/wordexp.c b/libc/misc/wordexp/wordexp.c
index 8167ed685..4a2b50b4e 100644
--- a/libc/misc/wordexp/wordexp.c
+++ b/libc/misc/wordexp/wordexp.c
@@ -787,6 +787,7 @@ parse_arith(char **word, size_t * word_length, size_t * max_length,
static void attribute_noreturn
exec_comm_child(char *comm, int *fildes, int showerr, int noexec)
{
+ int fd;
const char *args[4] = { _PATH_BSHELL, "-c", comm, NULL };
/* Execute the command, or just check syntax? */
@@ -794,13 +795,14 @@ exec_comm_child(char *comm, int *fildes, int showerr, int noexec)
args[1] = "-nc";
/* Redirect output. */
- dup2(fildes[1], 1);
- close(fildes[1]);
+ fd = fildes[1];
+ if (fd != 1) {
+ dup2(fd, 1);
+ close(fd);
+ }
/* Redirect stderr to /dev/null if we have to. */
if (showerr == 0) {
- int fd;
-
close(2);
fd = open(_PATH_DEVNULL, O_WRONLY);
if (fd >= 0 && fd != 2) {
@@ -812,7 +814,8 @@ exec_comm_child(char *comm, int *fildes, int showerr, int noexec)
/* Make sure the subshell doesn't field-split on our behalf. */
unsetenv("IFS");
- close(fildes[0]);
+ if (fildes[0] != 1)
+ close(fildes[0]);
execve(_PATH_BSHELL, (char *const *) args, __environ);
/* Bad. What now? */