X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Ftty.c;h=9fa0326cb0ca2d438eb181289d8cd3b0849b3d1b;hb=39c06d616dd4c9443ed390969e58cd53ca1e314d;hp=57f7465c48ceaf8c242d32d6a0de93e812432d02;hpb=0a5f7f46f597ae4fee342163de31c724096feb12;p=ppp.git diff --git a/pppd/tty.c b/pppd/tty.c index 57f7465..9fa0326 100644 --- a/pppd/tty.c +++ b/pppd/tty.c @@ -1,26 +1,79 @@ /* * tty.c - code for handling serial ports in pppd. * - * Copyright (C) 2000 Paul Mackerras. - * All rights reserved. + * Copyright (C) 2000-2002 Paul Mackerras. All rights reserved. * - * Portions Copyright (c) 1989 Carnegie Mellon University. - * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by Carnegie Mellon University. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Portions derived from main.c, which is: + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: tty.c,v 1.7 2002/09/12 22:34:47 paulus Exp $" +#define RCSID "$Id: tty.c,v 1.11 2003/03/03 05:11:46 paulus Exp $" #include #include @@ -55,7 +108,7 @@ int connect_tty __P((void)); void disconnect_tty __P((void)); void tty_close_fds __P((void)); void cleanup_tty __P((void)); -void tty_do_send_config __P((int, u_int32_t, int, int)); +int tty_do_send_config __P((int, u_int32_t, int, int)); static int setdevname __P((char *, char **, int)); static int setspeed __P((char *, char **, int)); @@ -561,6 +614,11 @@ int connect_tty() if (pipe(ipipe) < 0 || pipe(opipe) < 0) fatal("Couldn't create pipes for record option: %m"); + + /* don't leak these to the ptycommand */ + (void) fcntl(ipipe[0], F_SETFD, FD_CLOEXEC); + (void) fcntl(opipe[1], F_SETFD, FD_CLOEXEC); + ok = device_script(ptycommand, opipe[0], ipipe[1], 1) == 0 && start_charshunt(ipipe[0], opipe[1]); close(ipipe[0]); @@ -714,14 +772,14 @@ void cleanup_tty() * tty_do_send_config - set transmit-side PPP configuration. * We set the extended transmit ACCM here as well. */ -void +int tty_do_send_config(mtu, accm, pcomp, accomp) int mtu; u_int32_t accm; int pcomp, accomp; { tty_set_xaccm(xmit_accm); - tty_send_config(mtu, accm, pcomp, accomp); + return tty_send_config(mtu, accm, pcomp, accomp); } /* @@ -829,7 +887,7 @@ start_charshunt(ifd, ofd) { int cpid; - cpid = fork(); + cpid = safe_fork(); if (cpid == -1) { error("Can't fork process for character shunt: %m"); return 0; @@ -841,7 +899,6 @@ start_charshunt(ifd, ofd) if (getuid() != uid) fatal("setuid failed"); setgid(getgid()); - sys_close(); if (!nodetach) log_to_fd = -1; charshunt(ifd, ofd, record_file); @@ -939,6 +996,13 @@ charshunt(ifd, ofd, record_file) signal(SIGXFSZ, SIG_DFL); #endif + /* + * Check that the fds won't overrun the fd_sets + */ + if (ifd >= FD_SETSIZE || ofd >= FD_SETSIZE || pty_master >= FD_SETSIZE) + fatal("internal error: file descriptor too large (%d, %d, %d)", + ifd, ofd, pty_master); + /* * Open the record file if required. */