From 80a2e37b4e4cccb0111b3e1b0f02f2882f43ded9 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 6 Sep 2015 19:56:44 +0000 Subject: 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@ --- usr.sbin/wsfontload/wsfontload.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'usr.sbin/wsfontload') 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 -#include #include #include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include +#include #include @@ -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); -- cgit v1.2.3