Check for valid speeds in TIOCSET* and return EINVAL for incorrect

values instead of setting garbadge.
This commit is contained in:
Andrey A. Chernov 1995-08-01 23:27:36 +00:00
parent 765d5b0d6f
commit 7a82fc7855
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=9847
2 changed files with 23 additions and 8 deletions

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)tty.c 8.8 (Berkeley) 1/21/94
* $Id: tty.c,v 1.65 1995/07/31 22:48:33 bde Exp $
* $Id: tty.c,v 1.66 1995/07/31 22:50:01 bde Exp $
*/
/*-
@ -175,6 +175,12 @@ char const char_type[] = {
#undef TB
#undef VT
int validspeed[] = {
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200
};
#define MAX_SPEED (sizeof(validspeed)/sizeof(*validspeed) - 1)
/* Macros to clear/set/test flags. */
#define SET(t, f) (t) |= (f)
#define CLR(t, f) (t) &= ~(f)
@ -823,6 +829,18 @@ ttioctl(tp, cmd, data, flag)
case TIOCSETAW: /* drain output, set */
case TIOCSETAF: { /* drn out, fls in, set */
register struct termios *t = (struct termios *)data;
register int i;
for (i = MAX_SPEED; i >= 0; i--)
if (t->c_ispeed == validspeed[i])
break;
if (i < 0)
return (EINVAL);
for (i = MAX_SPEED; i >= 0; i--)
if (t->c_ospeed == validspeed[i])
break;
if (i < 0)
return (EINVAL);
s = spltty();
if (cmd == TIOCSETAW || cmd == TIOCSETAF) {

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tty_compat.c 8.1 (Berkeley) 6/10/93
* $Id: tty_compat.c,v 1.12 1995/04/11 17:54:25 ache Exp $
* $Id: tty_compat.c,v 1.13 1995/05/30 08:06:09 rgrimes Exp $
*/
/*
@ -78,10 +78,7 @@ static struct speedtab compatspeeds[] = {
{ 0, 0 },
{ -1, -1 },
};
static int compatspcodes[] = {
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
};
extern int validspeed[]; /* in tty.c */
int ttsetcompat(tp, com, data, term)
register struct tty *tp;
@ -98,11 +95,11 @@ int ttsetcompat(tp, com, data, term)
if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
return(EINVAL);
else
term->c_ispeed = compatspcodes[speed];
term->c_ispeed = validspeed[speed];
if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
return(EINVAL);
else
term->c_ospeed = compatspcodes[speed];
term->c_ospeed = validspeed[speed];
term->c_cc[VERASE] = sg->sg_erase;
term->c_cc[VKILL] = sg->sg_kill;
tp->t_flags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffff);