summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>2025-10-11 15:46:06 +0000
committerderaadt <>2025-10-11 15:46:06 +0000
commitf690640165ccfa300db43b4a8e0d48a2ac660993 (patch)
tree31dd9bbfc54beb0e5f996c9e49fe0e6c118e1c6c /src
parent43419247d48fcba182defe04d984a4fc8ab42654 (diff)
downloadopenbsd-f690640165ccfa300db43b4a8e0d48a2ac660993.tar.gz
openbsd-f690640165ccfa300db43b4a8e0d48a2ac660993.tar.bz2
openbsd-f690640165ccfa300db43b4a8e0d48a2ac660993.zip
use strtonum() instead of atoi(), and error out for bad numbersHEADmaster
This generates a host-order number, so the ntohs() for getservbyport() was wrong, that should always have been htons(). The transform is the same, but misleading. ok tb
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/nc/netcat.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index e3c9c939e2..766da6e667 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.234 2025/06/24 13:37:11 tb Exp $ */ 1/* $OpenBSD: netcat.c,v 1.235 2025/10/11 15:46:06 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * Copyright (c) 2015 Bob Beck. All rights reserved. 4 * Copyright (c) 2015 Bob Beck. All rights reserved.
@@ -1542,7 +1542,12 @@ connection_info(const char *host, const char *port, const char *proto,
1542 1542
1543 /* Look up service name unless -n. */ 1543 /* Look up service name unless -n. */
1544 if (!nflag) { 1544 if (!nflag) {
1545 sv = getservbyport(ntohs(atoi(port)), proto); 1545 const char *errstr;
1546
1547 int p = strtonum(port, 1, PORT_MAX, &errstr);
1548 if (errstr)
1549 errx(1, "port number %s: %s", errstr, port);
1550 sv = getservbyport(htons(p), proto);
1546 if (sv != NULL) 1551 if (sv != NULL)
1547 service = sv->s_name; 1552 service = sv->s_name;
1548 } 1553 }