diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2024-11-04 11:12:53 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2024-11-04 11:12:53 +0000 |
commit | b93894210572b560e86f15d57119109dca759fad (patch) | |
tree | f38149e7f2e08271b2dc657dcf1732f10af4822a | |
parent | 625f200757358d846bf0a49fa6282d1a3bcda0f5 (diff) |
Some atoi -> strtonum conversions; ok denis
-rw-r--r-- | usr.sbin/pppd/chat/chat.c | 16 | ||||
-rw-r--r-- | usr.sbin/pppd/pppstats/pppstats.c | 11 | ||||
-rw-r--r-- | usr.sbin/pppd/sys-bsd.c | 10 |
3 files changed, 25 insertions, 12 deletions
diff --git a/usr.sbin/pppd/chat/chat.c b/usr.sbin/pppd/chat/chat.c index 058211a3eb3..596a83c4418 100644 --- a/usr.sbin/pppd/chat/chat.c +++ b/usr.sbin/pppd/chat/chat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chat.c,v 1.38 2024/08/17 15:42:20 denis Exp $ */ +/* $OpenBSD: chat.c,v 1.39 2024/11/04 11:12:52 deraadt Exp $ */ /* * Chat -- a program for automatic session establishment (i.e. dial @@ -213,6 +213,7 @@ int main(int, char *[]); int main(int argc, char **argv) { + const char *errstr; int option; tzset(); @@ -245,7 +246,9 @@ main(int argc, char **argv) break; case 't': - timeout = atoi(optarg); + timeout = strtonum(optarg, 0, 10000, &errstr); + if (errstr) + fatal(2, "-t %s: %s\n", optarg, errstr); break; case 'r': @@ -949,6 +952,8 @@ char *character(int c) */ void chat_send (char *s) { + const char *errstr; + if (say_next) { say_next = 0; s = clean(s,0); @@ -1076,8 +1081,11 @@ void chat_send (char *s) if (timeout_next) { timeout_next = 0; - timeout = atoi(s); - + timeout = strtonum(s, -1, 10000, &errstr); + if (errstr) { + logmsg("invalid timeout %s: %s\n", s, errstr); + timeout = -1; + } if (timeout <= 0) timeout = DEFAULT_CHAT_TIMEOUT; diff --git a/usr.sbin/pppd/pppstats/pppstats.c b/usr.sbin/pppd/pppstats/pppstats.c index 50c6c9d3f8d..300d5ec841c 100644 --- a/usr.sbin/pppd/pppstats/pppstats.c +++ b/usr.sbin/pppd/pppstats/pppstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pppstats.c,v 1.14 2024/08/10 05:32:28 jsg Exp $ */ +/* $OpenBSD: pppstats.c,v 1.15 2024/11/04 11:12:52 deraadt Exp $ */ /* * print PPP statistics: @@ -305,6 +305,7 @@ intpr(void) int main(int argc, char *argv[]) { + const char *errstr; int c; struct ifreq ifr; @@ -328,13 +329,13 @@ main(int argc, char *argv[]) zflag = 1; break; case 'c': - count = atoi(optarg); - if (count <= 0) + count = strtonum(optarg, 1, 1000, &errstr); + if (errstr) usage(); break; case 'w': - interval = atoi(optarg); - if (interval <= 0) + interval = strtonum(optarg, 1, 1000, &errstr); + if (errstr) usage(); break; default: diff --git a/usr.sbin/pppd/sys-bsd.c b/usr.sbin/pppd/sys-bsd.c index 033e5772edf..007edf5f4c2 100644 --- a/usr.sbin/pppd/sys-bsd.c +++ b/usr.sbin/pppd/sys-bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys-bsd.c,v 1.36 2024/08/17 09:52:11 denis Exp $ */ +/* $OpenBSD: sys-bsd.c,v 1.37 2024/11/04 11:12:52 deraadt Exp $ */ /* * sys-bsd.c - System-dependent procedures for setting up @@ -1409,6 +1409,7 @@ GetMask(u_int32_t addr) int lock(char *dev) { + const char *errstr; char hdb_lock_buffer[12]; int fd, n; pid_t pid; @@ -1429,8 +1430,11 @@ lock(char *dev) close(fd); } else { hdb_lock_buffer[n] = 0; - pid = atoi(hdb_lock_buffer); - if (kill(pid, 0) == -1 && errno == ESRCH) { + pid = strtonum(hdb_lock_buffer, 1, 65535, &errstr); + if (errstr) + syslog(LOG_NOTICE, "lock file %s contains garbage: %s\n", + dev, errstr); + else if (kill(pid, 0) == -1 && errno == ESRCH) { /* pid no longer exists - remove the lock file */ if (unlink(lock_file) == 0) { close(fd); |