[openssh-commits] [openssh] 30/87: upstream: don't count time spent in getaddrinfo() or obtaining
git+noreply at mindrot.org
git+noreply at mindrot.org
Fri Oct 30 20:21:07 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit 98ce8b4985781a265bf4715aa401fe6485c40e7b
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Fri Oct 30 03:13:52 2026 +0000
upstream: don't count time spent in getaddrinfo() or obtaining
the hostname to scan from stdin against active ssh-keyscan connections in
progress.
Avoids incorrectly timing out good hosts during unrelated stalled
lookups/reads
Anthropic ANT-2026-LU2X6L18
OpenBSD-Commit-ID: e73163fa4caf8e7b76078f58425c5fd3fd9d192c
---
ssh-keyscan.c | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index c43bebf12..0fb6e9fef 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.171 2026/09/02 00:37:59 djm Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.172 2026/10/30 03:13:52 djm Exp $ */
/*
* Copyright 1995, 1996 by David Mazieres <dm at lcs.mit.edu>.
*
@@ -352,10 +352,29 @@ keyprint(con *c, struct sshkey *key)
free(ohosts);
}
+/*
+ * Pending connections cannot be serviced while we are blocked outside
+ * the event loop (e.g. in getaddrinfo() or reading the host list), so
+ * don't count that time against their timeouts. Every deadline moves
+ * by the same amount, which keeps the timeout queue in order.
+ */
+static void
+conextend(const struct timespec *start)
+{
+ struct timespec blocked;
+ con *c;
+
+ monotime_ts(&blocked);
+ timespecsub(&blocked, start, &blocked);
+ TAILQ_FOREACH(c, &tq, c_link)
+ timespecadd(&c->c_ts, &blocked, &c->c_ts);
+}
+
static int
tcpconnect(char *host)
{
struct addrinfo hints, *ai, *aitop;
+ struct timespec start;
char strport[NI_MAXSERV];
int gaierr, s = -1;
@@ -363,7 +382,10 @@ tcpconnect(char *host)
memset(&hints, 0, sizeof(hints));
hints.ai_family = IPv4or6;
hints.ai_socktype = SOCK_STREAM;
- if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) {
+ monotime_ts(&start);
+ gaierr = getaddrinfo(host, strport, &hints, &aitop);
+ conextend(&start);
+ if (gaierr != 0) {
error("getaddrinfo %s: %s", host, ssh_gai_strerror(gaierr));
return -1;
}
@@ -674,6 +696,8 @@ main(int argc, char **argv)
int opt, fopt_count = 0, j;
char *tname, *cp, *line = NULL;
size_t linesize = 0;
+ ssize_t linelen;
+ struct timespec start;
FILE *fp;
extern int optind;
@@ -809,7 +833,12 @@ main(int argc, char **argv)
fatal("%s: %s: %s", __progname,
fp == stdin ? "<stdin>" : argv[j], strerror(errno));
- while (getline(&line, &linesize, fp) != -1) {
+ for (;;) {
+ monotime_ts(&start);
+ linelen = getline(&line, &linesize, fp);
+ conextend(&start);
+ if (linelen == -1)
+ break;
/* Chomp off trailing whitespace and comments */
if ((cp = strchr(line, '#')) == NULL)
cp = line + strlen(line) - 1;
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list