diff options
author | 2002-05-30 09:37:38 +0000 | |
---|---|---|
committer | 2002-05-30 09:37:38 +0000 | |
commit | 13847bbc66a17913ad5724f668d2b99e39b1ee2f (patch) | |
tree | e89b6958f8a8e0c4e6e33d96c76a12c6c259dd38 | |
parent | Do not allow user to run authpf if user's shell is not /usr/sbin/authpf to (diff) | |
download | wireguard-openbsd-13847bbc66a17913ad5724f668d2b99e39b1ee2f.tar.xz wireguard-openbsd-13847bbc66a17913ad5724f668d2b99e39b1ee2f.zip |
Avoid spinning poll, and while we're at it more closely reproduce the
original netcat's timeout behaviour. Theo says go.
-rw-r--r-- | usr.bin/nc/netcat.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index 3a1e9c11937..67e33de4906 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.48 2002/05/29 09:23:25 deraadt Exp $ */ +/* $OpenBSD: netcat.c,v 1.49 2002/05/30 09:37:38 hugh Exp $ */ /* * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * @@ -66,7 +66,7 @@ int vflag; /* Verbosity */ int xflag; /* Socks proxy */ int zflag; /* Port Scan Flag */ -int timeout; +int timeout = -1; int family = AF_UNSPEC; char *portlist[PORT_MAX]; @@ -160,6 +160,9 @@ main(int argc, char *argv[]) timeout = (int)strtoul(optarg, &endp, 10); if (timeout < 0 || *endp != '\0') errx(1, "timeout cannot be negative"); + if (timeout >= (INT_MAX / 1000)) + errx(1, "timeout too large"); + timeout *= 1000; break; case 'x': xflag = 1; @@ -548,13 +551,16 @@ readwrite(int nfd) if (iflag) sleep(iflag); - if (poll(pfd, 2, timeout) < 0) { + if ((n = poll(pfd, 2, timeout)) < 0) { close(nfd); close(wfd); free(pfd); errx(1, "Polling Error"); } + if (n == 0) + return; + if (pfd[0].revents & POLLIN) { if ((n = read(nfd, buf, sizeof(buf))) <= 0) { return; |