NetBSD Problem Report #58834
From www@netbsd.org Tue Nov 19 22:05:17 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id D885D1A9238
for <gnats-bugs@gnats.NetBSD.org>; Tue, 19 Nov 2024 22:05:17 +0000 (UTC)
Message-Id: <20241119220515.E557C1A923B@mollari.NetBSD.org>
Date: Tue, 19 Nov 2024 22:05:15 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: whois(1) spuriously fails with exit status 65=EHOSTUNREACH on v4-only hosts
X-Send-Pr-Version: www-1.0
>Number: 58834
>Category: bin
>Synopsis: whois(1) spuriously fails with exit status 65=EHOSTUNREACH on v4-only hosts
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Nov 19 22:10:00 +0000 2024
>Originator: Taylor R Campbell
>Release: current, 10, 9, ...
>Organization:
The NetBSDv6 Whoisdation
>Environment:
>Description:
On certain inputs, when run on hosts without IPv6 connectivity, whois(1) will successfully query WHOIS information, print it to stdout, and then exit with status 65=EHOSTUNREACH instead of status 0 as expected.
Example:
$ whois 4.2.2.1 >/dev/null; echo $?
65
This happens because the variable `error', which is used to record the last errno value in a loop over getaddrinfo(3) results in the event that they all fail in order to print an error message, is reused for recursive whois results and the final return value later on:
199 for (s = -1, ai = res; ai != NULL; ai = ai->ai_next) {
200 s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
201 if (s < 0) {
202 error = errno;
203 reason = "socket";
204 continue;
205 }
...
214 }
215 freeaddrinfo(res);
216 if (s < 0) {
217 if (reason) {
218 errno = error;
219 warn("%s: %s", server, reason);
220 } else
221 warnx("Unknown error in connection attempt");
222 return (1);
223 }
... /* NOTE: error is not reset to zero here */
284 if (nhost != NULL) {
285 error = whois(query, nhost, port, 0);
286 free(nhost);
287 }
288
289 return (error);
https://nxr.netbsd.org/xref/src/usr.bin/whois/whois.c?r=1.38#199
>How-To-Repeat:
1. set up a host with no IPv6 connectivity but DNS answers that have AAAA records for WHOIS servers
2. run a whois(1) with an input whose WHOIS server has AAAA records, e.g. an IP address for which whois.arin.net will be queried
3. examine the process's exit status
>Fix:
reset local variable `error' to zero at line 224 in whois.c rev. 1.38
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.