mirror of
https://github.com/nmap/nmap.git
synced 2026-11-28 10:30:14 +00:00
Honor -i idle timeout in Ncat HTTP proxy mode
ncat_http_server() passed a NULL timeout to fselect(), so -i/--idle-timeout was silently ignored: the accept loop blocked forever (leaving the 'Idle timeout expired' branch as dead code) and the post-CONNECT relay loop in handle_connect() never timed out idle connections either. Pass a timeval derived from o.idletimeout (milliseconds) to both selects, re-armed each iteration since select() may modify it. When -i is unset the timeout pointer stays NULL, preserving existing behavior. Relay timeout closes via the existing end label; error paths are unchanged. Fixes #824.
This commit is contained in:
parent
e135983b21
commit
71815ea13d
1 changed files with 23 additions and 2 deletions
|
|
@ -190,7 +190,16 @@ int ncat_http_server(void)
|
|||
logdebug("selecting, fdmax %d\n", listen_fdlist.fdmax);
|
||||
read_fds = listen_fds;
|
||||
|
||||
int fds_ready = fselect(listen_fdlist.fdmax + 1, &read_fds, NULL, NULL, NULL);
|
||||
/* Arm the idle timer, if requested. select() may modify the
|
||||
timeout, so it is re-initialized on every iteration. */
|
||||
struct timeval tv, *tvp = NULL;
|
||||
if (o.idletimeout > 0) {
|
||||
tvp = &tv;
|
||||
tv.tv_sec = o.idletimeout / 1000;
|
||||
tv.tv_usec = (o.idletimeout % 1000) * 1000;
|
||||
}
|
||||
|
||||
int fds_ready = fselect(listen_fdlist.fdmax + 1, &read_fds, NULL, NULL, tvp);
|
||||
|
||||
if (o.debug > 1)
|
||||
logdebug("select returned %d fds ready\n", fds_ready);
|
||||
|
|
@ -473,7 +482,19 @@ static int handle_connect(struct socket_buffer *client_sock,
|
|||
|
||||
r = m;
|
||||
|
||||
fselect(maxfd + 1, &r, NULL, NULL, NULL);
|
||||
/* Enforce the idle timeout on the relayed connection, if
|
||||
requested. select() may modify the timeout, so it is
|
||||
re-initialized on every iteration. */
|
||||
struct timeval tv, *tvp = NULL;
|
||||
if (o.idletimeout > 0) {
|
||||
tvp = &tv;
|
||||
tv.tv_sec = o.idletimeout / 1000;
|
||||
tv.tv_usec = (o.idletimeout % 1000) * 1000;
|
||||
}
|
||||
|
||||
rc = fselect(maxfd + 1, &r, NULL, NULL, tvp);
|
||||
if (rc == 0)
|
||||
goto end;
|
||||
|
||||
zmem(buf, sizeof(buf));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue