diff options
author | brian <brian@FreeBSD.org> | 1998-05-27 22:43:37 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1998-05-27 22:43:37 +0000 |
commit | 8001e72fd33ce2d0c42616fce9506a5848d47608 (patch) | |
tree | 84bffa02c3bd3f6e2fec100f4d3ad9bdedb4d9d4 /usr.sbin | |
parent | 02b6208b98526c48563bb198479cf2cbe0480d2b (diff) | |
download | FreeBSD-src-8001e72fd33ce2d0c42616fce9506a5848d47608.zip FreeBSD-src-8001e72fd33ce2d0c42616fce9506a5848d47608.tar.gz |
Don't assume stdout is a tty in interactive mode
Analyzed by: dmaddox@scsn.net (Donald J. Maddox)
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/main.c | 8 | ||||
-rw-r--r-- | usr.sbin/ppp/prompt.c | 36 |
2 files changed, 26 insertions, 18 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index f45a388..73945a5 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.124 1998/05/23 22:24:43 brian Exp $ + * $Id: main.c,v 1.125 1998/05/25 02:22:36 brian Exp $ * * TODO: */ @@ -80,7 +80,7 @@ static char pid_filename[MAXPATHLEN]; -static void DoLoop(struct bundle *, struct prompt *); +static void DoLoop(struct bundle *); static void TerminalStop(int); static const char *ex_desc(int); @@ -458,14 +458,14 @@ main(int argc, char **argv) #endif log_Printf(LogPHASE, "PPP Started (%s mode).\n", mode2Nam(mode)); - DoLoop(bundle, prompt); + DoLoop(bundle); AbortProgram(EX_NORMAL); return EX_NORMAL; } static void -DoLoop(struct bundle *bundle, struct prompt *prompt) +DoLoop(struct bundle *bundle) { fd_set rfds, wfds, efds; int i, nfds; diff --git a/usr.sbin/ppp/prompt.c b/usr.sbin/ppp/prompt.c index 19c6cba..bb10f4b 100644 --- a/usr.sbin/ppp/prompt.c +++ b/usr.sbin/ppp/prompt.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: prompt.c,v 1.2 1998/05/21 21:47:57 brian Exp $ + * $Id: prompt.c,v 1.3 1998/05/23 22:24:48 brian Exp $ */ #include <sys/param.h> @@ -285,13 +285,19 @@ prompt_Create(struct server *s, struct bundle *bundle, int fd) p->desc.Write = prompt_Write; if (fd == PROMPT_STD) { + char *tty = ttyname(STDIN_FILENO); + + if (!tty) { + free(p); + return NULL; + } p->fd_in = STDIN_FILENO; p->fd_out = STDOUT_FILENO; p->Term = stdout; p->owner = NULL; p->auth = LOCAL_AUTH; p->src.type = "Controller"; - strncpy(p->src.from, ttyname(p->fd_out), sizeof p->src.from - 1); + strncpy(p->src.from, tty, sizeof p->src.from - 1); p->src.from[sizeof p->src.from - 1] = '\0'; tcgetattr(p->fd_in, &p->oldtio); /* Save original tty mode */ } else { @@ -315,18 +321,20 @@ prompt_Create(struct server *s, struct bundle *bundle, int fd) void prompt_Destroy(struct prompt *p, int verbose) { - if (p->Term != stdout) { - fclose(p->Term); - close(p->fd_in); - if (p->fd_out != p->fd_in) - close(p->fd_out); - if (verbose) - log_Printf(LogPHASE, "%s: Client connection dropped.\n", p->src.from); - } else - prompt_TtyOldMode(p); - - log_UnRegisterPrompt(p); - free(p); + if (p) { + if (p->Term != stdout) { + fclose(p->Term); + close(p->fd_in); + if (p->fd_out != p->fd_in) + close(p->fd_out); + if (verbose) + log_Printf(LogPHASE, "%s: Client connection dropped.\n", p->src.from); + } else + prompt_TtyOldMode(p); + + log_UnRegisterPrompt(p); + free(p); + } } void |