mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* bootstrap: Add stdio-safer, unistd-safer modules.
Remove m4/glibc2.m4 (introduced by latest gnulib, but we don't need it). * lib/.cvsignore: Add dup-safer.c, fd-safer.c, fopen-safer.c, stdio-safer.h, unistd-safer.h. * lib/subpipe.c: Include "unistd-safer.h". (create_subpipe): Make sure all the newly-created file descriptors are > 2, so that diagnostics don't get sent down them (which might cause Bison to hang, in theory). * m4/.cvsignore: Add stdio-safer.m4, unistd-safer.m4. * src/files.c (xfopen): Use fopen_safer, not fopen.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* Subprocesses with pipes.
|
||||
|
||||
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -68,6 +68,7 @@
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
#include "unistd-safer.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(Msgid) gettext (Msgid)
|
||||
@@ -105,15 +106,13 @@ create_subpipe (char const * const *argv, int fd[2])
|
||||
int to_out_fd;
|
||||
pid_t pid;
|
||||
|
||||
if (pipe (pipe_fd) != 0)
|
||||
if (pipe (pipe_fd) != 0
|
||||
|| (to_in_fd = fd_safer (pipe_fd[0])) < 0
|
||||
|| (to_out_fd = fd_safer (pipe_fd[1])) < 0
|
||||
|| pipe (pipe_fd) != 0
|
||||
|| (from_in_fd = fd_safer (pipe_fd[0])) < 0
|
||||
|| (from_out_fd = fd_safer (pipe_fd[1])) < 0)
|
||||
error (EXIT_FAILURE, errno, "pipe");
|
||||
to_in_fd = pipe_fd[0];
|
||||
to_out_fd = pipe_fd[1];
|
||||
|
||||
if (pipe (pipe_fd) != 0)
|
||||
error (EXIT_FAILURE, errno, "pipe");
|
||||
from_in_fd = pipe_fd[0];
|
||||
from_out_fd = pipe_fd[1];
|
||||
|
||||
pid = vfork ();
|
||||
if (pid < 0)
|
||||
@@ -124,23 +123,16 @@ create_subpipe (char const * const *argv, int fd[2])
|
||||
/* Child. */
|
||||
close (to_out_fd);
|
||||
close (from_in_fd);
|
||||
|
||||
if (to_in_fd != STDIN_FILENO)
|
||||
{
|
||||
dup2 (to_in_fd, STDIN_FILENO);
|
||||
close (to_in_fd);
|
||||
}
|
||||
if (from_out_fd != STDOUT_FILENO)
|
||||
{
|
||||
dup2 (from_out_fd, STDOUT_FILENO);
|
||||
close (from_out_fd);
|
||||
}
|
||||
dup2 (to_in_fd, STDIN_FILENO);
|
||||
close (to_in_fd);
|
||||
dup2 (from_out_fd, STDOUT_FILENO);
|
||||
close (from_out_fd);
|
||||
|
||||
/* The cast to (char **) rather than (char * const *) is needed
|
||||
for portability to older hosts with a nonstandard prototype
|
||||
for execvp. */
|
||||
execvp (argv[0], (char **) argv);
|
||||
|
||||
|
||||
_exit (errno == ENOENT ? 127 : 126);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user