NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/53782: getaddrinfo: error messages swapped?



>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.



Home | Main Index | Thread Index | Old Index