aboutsummaryrefslogtreecommitdiffhomepage
path: root/exec.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-01-08 10:44:05 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-01-08 10:44:05 -0800
commit34db67680dd307bf5c60f46b1f723be2c803e32a (patch)
treea67dd9dcf7eadf15427596d1398f4cafac118459 /exec.cpp
parent7864d0d416519774c614148920530bc7da4a3e3b (diff)
Ignore user-supplied fd redirections above 2 for builtins
Prevents e.g. specifying an fd which corresponds to the history file as the stdin for builtin_source
Diffstat (limited to 'exec.cpp')
-rw-r--r--exec.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/exec.cpp b/exec.cpp
index 18d5313d..97229180 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -366,7 +366,7 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t *out_chain, s
}
opened_fds.push_back(fd);
- out.reset(new io_fd_t(in->fd, fd));
+ out.reset(new io_fd_t(in->fd, fd, false));
break;
}
@@ -867,7 +867,7 @@ void exec_job(parser_t &parser, job_t *j)
case INTERNAL_BUILTIN:
{
- int local_builtin_stdin = 0;
+ int local_builtin_stdin = STDIN_FILENO;
bool close_stdin = false;
/*
@@ -887,7 +887,11 @@ void exec_job(parser_t &parser, job_t *j)
case IO_FD:
{
CAST_INIT(const io_fd_t *, in_fd, in.get());
- local_builtin_stdin = in_fd->old_fd;
+ /* Ignore user-supplied fd redirections from an fd other than the standard ones. e.g. in source <&3 don't actually read from fd 3, which is internal to fish. We still respect this redirection in that we pass it on as a block IO to the code that source runs, and therefore this is not an error. Non-user supplied fd redirections come about through transmogrification, and we need to respect those here. */
+ if (! in_fd->user_supplied || (in_fd->old_fd >= 0 && in_fd->old_fd < 3))
+ {
+ local_builtin_stdin = in_fd->old_fd;
+ }
break;
}
case IO_PIPE: