summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-10-28 20:58:39 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-10-28 20:58:39 +0000
commitcbb354c6b63eda7b79f4c2b5cbd1839f5e364a9b (patch)
tree7fce4d87f5b1726b6c892030e77202b92bc398d8
parentdac824dc8b08d86cd5ef1eb4a31dc0a514fabd8d (diff)
Use strtonum() instead of atoi() so that ridiculous sloppy things like
ispeed -38400 baud; ospeed 38400 baud; 24 rows; 80 columns; and % stty rows -45; stty size 65491 80 don't happen. ok millert guenther
-rw-r--r--bin/stty/key.c13
-rw-r--r--bin/stty/stty.c8
2 files changed, 16 insertions, 5 deletions
diff --git a/bin/stty/key.c b/bin/stty/key.c
index 22af3088caa..a3574ec1a29 100644
--- a/bin/stty/key.c
+++ b/bin/stty/key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key.c,v 1.13 2009/10/27 23:59:22 deraadt Exp $ */
+/* $OpenBSD: key.c,v 1.14 2009/10/28 20:58:38 deraadt Exp $ */
/* $NetBSD: key.c,v 1.11 1995/09/07 06:57:11 jtc Exp $ */
/*-
@@ -35,6 +35,7 @@
#include <err.h>
#include <errno.h>
#include <stdlib.h>
+#include <limits.h>
#include <stdio.h>
#include <string.h>
@@ -155,8 +156,11 @@ f_cbreak(struct info *ip)
void
f_columns(struct info *ip)
{
+ const char *error;
- ip->win.ws_col = atoi(ip->arg);
+ ip->win.ws_col = strtonum(ip->arg, 0, USHRT_MAX, &error);
+ if (error)
+ err(1, "cols %s", ip->arg);
ip->wset = 1;
}
@@ -265,8 +269,11 @@ f_raw(struct info *ip)
void
f_rows(struct info *ip)
{
+ const char *error;
- ip->win.ws_row = atoi(ip->arg);
+ ip->win.ws_row = strtonum(ip->arg, 0, USHRT_MAX, &error);
+ if (error)
+ err(1, "rows %s", ip->arg);
ip->wset = 1;
}
diff --git a/bin/stty/stty.c b/bin/stty/stty.c
index 210a7368393..04e8f5eb413 100644
--- a/bin/stty/stty.c
+++ b/bin/stty/stty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stty.c,v 1.13 2009/10/27 23:59:22 deraadt Exp $ */
+/* $OpenBSD: stty.c,v 1.14 2009/10/28 20:58:38 deraadt Exp $ */
/* $NetBSD: stty.c,v 1.11 1995/03/21 09:11:30 cgd Exp $ */
/*-
@@ -38,6 +38,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <limits.h>
#include <string.h>
#include <unistd.h>
@@ -111,9 +112,12 @@ args: argc -= optind;
continue;
if (isdigit(**argv)) {
+ const char *error;
int speed;
- speed = atoi(*argv);
+ speed = strtonum(*argv, 0, INT_MAX, &error);
+ if (error)
+ err(1, "%s", *argv);
cfsetospeed(&i.t, speed);
cfsetispeed(&i.t, speed);
i.set = 1;