NetBSD Problem Report #53782

From dholland@netbsd.org  Thu Dec 13 04:50:47 2018
Return-Path: <dholland@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 7B2337A155
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 13 Dec 2018 04:50:47 +0000 (UTC)
Message-Id: <20181213045047.3BC5A84D61@mail.netbsd.org>
Date: Thu, 13 Dec 2018 04:50:47 +0000 (UTC)
From: dholland@NetBSD.org
Reply-To: dholland@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: getaddrinfo: error messages swapped?
X-Send-Pr-Version: 3.95

>Number:         53782
>Category:       lib
>Synopsis:       getaddrinfo: error messages swapped?
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 13 04:55:00 +0000 2018
>Originator:     David A. Holland
>Release:        NetBSD 8.99.27 (20181212)
>Organization:
>Environment:
System: NetBSD valkyrie 8.99.25 NetBSD 8.99.25 (VALKYRIE) #27: Sun Nov  4 03:37:03 EST 2018  dholland@valkyrie:/usr/src/sys/arch/amd64/compile/VALKYRIE amd64
Architecture: x86_64
Machine: amd64
>Description:

	Currently, getaddrinfo (lib/libc/net/getaddrinfo.c) contains
	this snippet starting at line 608:

		if (hostname == NULL)
			ERR(EAI_NODATA);
		if (pai->ai_flags & AI_NUMERICHOST)
			ERR(EAI_NONAME);

	This is after numeric hostnames have been handled, so if
	AI_NUMERICHOST is set and no result has been produced, the
	operation has failed. (It is about to try looking up hostnames
	in DNS.)

	Meanwhile, if hostname is NULL, it means the hostname argument
	of getaddrinfo was NULL.

	So if at this point the passed-in hostname is NULL, it fails
	with EAI_NODATA, and if it was supposed to be a numeric
	address but wasn't a valid numeric address, it fails with
	EAI_NONAME.

	The problem with this is that EAI_NODATA means "No address
	associated with hostname" and EAI_NONAME means (after I just
	improved it a moment ago) "hostname or servname not provided
	or not known".

	This seems backwards.

	Am I missing something or should the error codes be swapped?


	(Note that I just committed a different fix where the wrong
	one of these codes was used, but that one was readily
	testable.)


>How-To-Repeat:
	Code inspection.

>Fix:
	Trivial.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.