Bug 21092

Summary: _gethostbynis function does not set h_errno on failure
Product: Base System Reporter: ak03 <ak03>
Component: binAssignee: Jacques Vidrine <nectar>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   

Description ak03 2000-09-07 16:40:00 UTC
If NIS is selected as the only source used for the name resolution in
host.conf or in nsswitch.conf on newer -CURRENT and then name resolution
attempted for an unknown hostname using gethostbyname* functions, h_error 
is not getting set correctly when resolution fails. 

It seems like _gethostbynis function fails to set h_errno variable to the 
appropriate value when returning. All other functions in the family, i.e.
_gethostbydns and _gethostbyht, do so.

Without attached patch, the following command returns with strange message:

[ak03@kanpc ~]$ ping sjkjss
ping: cannot resolve sjkjss: Resolver Error 0 (no error)
  
With patch applied, ping produces more reasonable output:
[ak03@kanpc ~]$ ping sjkjss
ping: cannot resolve sjkjss: Unknown host

How-To-Repeat: 
Comment out non-nis entries in host.conf or nsswitch.conf and try to ping 
some unknown host.


Index: gethostbynis.c
===================================================================
RCS file: /usr/ncvs/src/lib/libc/net/gethostbynis.c,v
retrieving revision 1.10
diff -u -r1.10 gethostbynis.c
--- gethostbynis.c	1999/08/28 00:00:06	1.10
+++ gethostbynis.c	2000/09/07 15:12:50
@@ -76,15 +76,20 @@
 	case AF_INET6:
 		size = NS_IN6ADDRSZ;
 		errno = EAFNOSUPPORT;
+		h_errno = NETDB_INTERNAL;
 		return NULL;
 	}
 
 	if (domain == (char *)NULL)
-		if (yp_get_default_domain (&domain))
+		if (yp_get_default_domain (&domain)) {
+			h_errno = NETDB_INTERNAL;
 			return ((struct hostent *)NULL);
+		}
 
-	if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+	if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) {
+		h_errno = HOST_NOT_FOUND;
 		return ((struct hostent *)NULL);
+	}
 
 	/* avoid potential memory leak */
 	bcopy((char *)result, (char *)&ypbuf, resultlen);
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2000-09-08 13:50:03 UTC
Responsible Changed
From-To: freebsd-bugs->nectar

Over to maintainer.
Comment 2 Jacques Vidrine freebsd_committer freebsd_triage 2000-10-01 17:40:58 UTC
State Changed
From-To: open->closed

Committed to 4-STABLE, r1.10.2.1