aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/ppp/chat.c
diff options
context:
space:
mode:
authorBrian Somers <brian@FreeBSD.org>1999-08-17 14:59:05 +0000
committerBrian Somers <brian@FreeBSD.org>1999-08-17 14:59:05 +0000
commit44e73c1254f754085006f3e66bfa227d862cc247 (patch)
tree7e450dba002b01f2dfcc4f7beab3b37cf854e9ad /usr.sbin/ppp/chat.c
parente760dabd67123d1953ae5daf222d17eaa518aa3e (diff)
Set the close-on-exec flag for all unused descriptors when
exec()ing other programs.
Notes
Notes: svn path=/head/; revision=49976
Diffstat (limited to 'usr.sbin/ppp/chat.c')
-rw-r--r--usr.sbin/ppp/chat.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index 8819fd8eed25..08c89ccd2e40 100644
--- a/usr.sbin/ppp/chat.c
+++ b/usr.sbin/ppp/chat.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: chat.c,v 1.58 1999/06/26 02:54:24 brian Exp $
+ * $Id: chat.c,v 1.59 1999/06/26 02:54:36 brian Exp $
*/
#include <sys/param.h>
@@ -682,7 +682,7 @@ ExecStr(struct physical *physical, char *command, char *out, int olen)
pid_t pid;
int fids[2];
char *argv[MAXARGS], *vector[MAXARGS], *startout, *endout;
- int stat, nb, argc;
+ int stat, nb, argc, i;
log_Printf(LogCHAT, "Exec: %s\n", command);
argc = MakeArgs(command, vector, VECSIZE(vector));
@@ -698,19 +698,20 @@ ExecStr(struct physical *physical, char *command, char *out, int olen)
if ((pid = fork()) == 0) {
close(fids[0]);
timer_TermService();
- fids[1] = fcntl(fids[1], F_DUPFD, 4);
+ if (fids[1] == STDIN_FILENO)
+ fids[1] = dup(fids[1]);
dup2(physical->fd, STDIN_FILENO);
- dup2(STDIN_FILENO, STDOUT_FILENO);
dup2(fids[1], STDERR_FILENO);
+ dup2(STDIN_FILENO, STDOUT_FILENO);
close(3);
- if (open(_PATH_TTY, O_RDWR) == 3)
- fcntl(3, F_SETFD, 0); /* Clear close-on-exec flag */
- else
- fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
+ if (open(_PATH_TTY, O_RDWR) != 3)
+ open(_PATH_DEVNULL, O_RDWR); /* Leave it closed if it fails... */
+ for (i = getdtablesize(); i > 3; i--)
+ fcntl(i, F_SETFD, 1);
setuid(geteuid());
execvp(argv[0], argv);
fprintf(stderr, "execvp: %s: %s\n", argv[0], strerror(errno));
- exit(127);
+ _exit(127);
} else {
char *name = strdup(vector[0]);