diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2015-09-06 19:56:44 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2015-09-06 19:56:44 +0000 |
commit | 80a2e37b4e4cccb0111b3e1b0f02f2882f43ded9 (patch) | |
tree | 4f76f0eb89dafd10b93bb5e2793cc6b7f84a297c /usr.sbin/wsfontload | |
parent | 48d517b705b0554dfe8c69ee57c54c6ea4ccbaec (diff) |
Avoid floating point exception when an invalid font width was specified.
Also print actually helpful error messages when command line arguments
are invalid.
ok miod@
Diffstat (limited to 'usr.sbin/wsfontload')
-rw-r--r-- | usr.sbin/wsfontload/wsfontload.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/usr.sbin/wsfontload/wsfontload.c b/usr.sbin/wsfontload/wsfontload.c index f4cda028aec..313d4e9d240 100644 --- a/usr.sbin/wsfontload/wsfontload.c +++ b/usr.sbin/wsfontload/wsfontload.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsfontload.c,v 1.14 2015/02/09 23:00:15 deraadt Exp $ */ +/* $OpenBSD: wsfontload.c,v 1.15 2015/09/06 19:56:43 tobias Exp $ */ /* $NetBSD: wsfontload.c,v 1.2 2000/01/05 18:46:43 ad Exp $ */ /* @@ -33,17 +33,18 @@ * */ -#include <sys/types.h> -#include <sys/time.h> #include <sys/ioctl.h> #include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <err.h> +#include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> -#include <fcntl.h> -#include <unistd.h> #include <string.h> -#include <err.h> +#include <unistd.h> #include <dev/wscons/wsconsio.h> @@ -90,6 +91,7 @@ main(int argc, char *argv[]) struct stat stat; size_t len; void *buf; + const char *errstr; wsdev = DEFDEV; memset(&f, 0, sizeof f); @@ -103,14 +105,14 @@ main(int argc, char *argv[]) wsdev = optarg; break; case 'w': - if (sscanf(optarg, "%d", &f.fontwidth) != 1) - errx(1, "invalid font width of %d", - f.fontwidth); + f.fontwidth = strtonum(optarg, 1, UINT_MAX, &errstr); + if (errstr) + errx(1, "font width is %s: %s", errstr, optarg); break; case 'h': - if (sscanf(optarg, "%d", &f.fontheight) != 1) - errx(1, "invalid font height of %d", - f.fontheight); + f.fontheight = strtonum(optarg, 1, UINT_MAX, &errstr); + if (errstr) + errx(1, "font height is %s: %s", errstr, optarg); break; case 'e': f.encoding = getencoding(optarg); |