summaryrefslogtreecommitdiffstats
path: root/libexec/spamd
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2015-04-18 18:28:36 +0000
committerderaadt <deraadt@openbsd.org>2015-04-18 18:28:36 +0000
commita47b6461a15f74beac188483616126ed5e987f93 (patch)
tree4453af12f02f369f89c8895bcfef1820fdb8576d /libexec/spamd
parentDelete the wrapper functions mdoc_meta(), man_meta(), mdoc_node(), (diff)
downloadwireguard-openbsd-a47b6461a15f74beac188483616126ed5e987f93.tar.xz
wireguard-openbsd-a47b6461a15f74beac188483616126ed5e987f93.zip
Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way. Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert
Diffstat (limited to 'libexec/spamd')
-rw-r--r--libexec/spamd/spamd.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c
index 8c1ddb0ec31..3f4933cf3ec 100644
--- a/libexec/spamd/spamd.c
+++ b/libexec/spamd/spamd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: spamd.c,v 1.126 2015/03/12 20:07:20 millert Exp $ */
+/* $OpenBSD: spamd.c,v 1.127 2015/04/18 18:28:37 deraadt Exp $ */
/*
* Copyright (c) 2015 Henning Brauer <henning@openbsd.org>
@@ -1246,22 +1246,21 @@ main(int argc, char *argv[])
bind_address = optarg;
break;
case 'B':
- i = atoi(optarg);
- maxblack = i;
+ maxblack = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr)
+ errx(1, "-B %s: %s", optarg, errstr);
break;
case 'c':
- i = atoi(optarg);
- if (i > maxfiles) {
- fprintf(stderr,
- "%d > system max of %d connections\n",
- i, maxfiles);
+ maxcon = strtonum(optarg, 1, maxfiles, &errstr);
+ if (errstr) {
+ fprintf(stderr, "-c %s: %sn", optarg, errstr);
usage();
}
- maxcon = i;
break;
case 'p':
- i = atoi(optarg);
- port = i;
+ port = strtonum(optarg, 1, USHRT_MAX, &errstr);
+ if (errstr)
+ errx(1, "-p %s: %s", optarg, errstr);
break;
case 'd':
debug = 1;
@@ -1290,16 +1289,14 @@ main(int argc, char *argv[])
errx(1, "-h arg too long");
break;
case 's':
- i = strtonum(optarg, 0, 10, &errstr);
+ stutter = strtonum(optarg, 0, 10, &errstr);
if (errstr)
usage();
- stutter = i;
break;
case 'S':
- i = strtonum(optarg, 0, 90, &errstr);
+ grey_stutter = strtonum(optarg, 0, 90, &errstr);
if (errstr)
usage();
- grey_stutter = i;
break;
case 'M':
low_prio_mx_ip = optarg;
@@ -1311,9 +1308,9 @@ main(int argc, char *argv[])
verbose = 1;
break;
case 'w':
- window = atoi(optarg);
- if (window <= 0)
- usage();
+ window = strtonum(optarg, 1, INT_MAX, &errstr);
+ if (errstr)
+ errx(1, "-w %s: %s", optarg, errstr);
break;
case 'Y':
if (sync_addhost(optarg, sync_port) != 0)