From 5e2022633a0037a1dd6b5cee78ff6bec4013013d Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Wed, 30 Jul 1997 10:05:18 +0000 Subject: [PATCH] fix a few problems with pty. warn about how if you only have 1 pty defined, your really getting 32. Also warn about how you can't have more than 256 pty's when your using DEVFS (non DEVFS can use more, just the makedev script doesn't know how to make >256). it also doesn't allocate more memory than needed in this case. Make sure that the signal passed in TIOCSIG isn't 0 as it might cause a panic. I personally haven't seen this happen, but after a similar bug in syscons crashed my machine, I'm acutely aware of this one. :) --- sys/kern/tty_pty.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index ee0b65334cc3..f721b413e976 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95 - * $Id: tty_pty.c,v 1.42 1997/03/23 03:36:28 bde Exp $ + * $Id: tty_pty.c,v 1.43 1997/03/24 12:03:06 bde Exp $ */ /* @@ -93,6 +93,19 @@ static struct cdevsw ptc_cdevsw = #if NPTY == 1 #undef NPTY #define NPTY 32 /* crude XXX */ +#warning You have only one pty defined, redefining to 32. +#endif + +#ifdef DEVFS +#define MAXUNITS (8 * 32) +static void *devfs_token_pts[MAXUNITS]; +static void *devfs_token_ptc[MAXUNITS]; +static const char jnames[] = "pqrsPQRS"; +#if NPTY > MAXUNITS +#undef NPTY +#define NPTY MAXUNITS +#warning Can't have more than 256 pty's with DEVFS defined. +#endif #endif #define BUFSIZ 100 /* Chunk size iomoved to/from user */ @@ -710,7 +723,8 @@ ptyioctl(dev, cmd, data, flag, p) break; case TIOCSIG: - if (*(unsigned int *)data >= NSIG) + if (*(unsigned int *)data >= NSIG || + *(unsigned int *)data == 0) return(EINVAL); if ((tp->t_lflag&NOFLSH) == 0) ttyflush(tp, FREAD|FWRITE); @@ -780,12 +794,6 @@ ptyioctl(dev, cmd, data, flag, p) } static ptc_devsw_installed = 0; -#ifdef DEVFS -#define MAXUNITS (8 * 32) -static void *devfs_token_pts[MAXUNITS]; -static void *devfs_token_ptc[MAXUNITS]; -static const char jnames[] = "pqrsPQRS"; -#endif static void ptc_drvinit(void *unused) @@ -802,11 +810,6 @@ ptc_drvinit(void *unused) cdevsw_add(&dev, &ptc_cdevsw, NULL); ptc_devsw_installed = 1; #ifdef DEVFS -/*XXX*/ -#if NPTY > MAXUNITS -#undef NPTY -#define NPTY MAXUNITS -#endif for ( i = 0 ; i