public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] getnameinfo fixes
@ 2006-08-28 10:09 Jakub Jelinek
  2006-08-28 16:24 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2006-08-28 10:09 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=204122
complains that getnameinfo suffers similar problem like getaddrinfo used to
6 years ago, namely that EAI_AGAIN is not returned when it should.
While looking at it, I noticed e.g. struct hostent *h = NULL; if (h == NULL)
{ ... } bogosity, AF_INET loop not checking herrno == NETDB_INTERNAL and
when returning EAI_SYSTEM setting errno to the saved errno value from when
getnameinfo was entered (but the standard says that for EAI_SYSTEM errno
should contain the error code).  I have also moved the error checking code
out of the loops, removing the need to duplicate the checks, all that
is needed to check in the loops is the NETDB_INTERNAL/ERANGE condition,
so that we can grow the buffer.

What I'm not 100% sure is what should we do in the herrno == TRY_AGAIN
case, when NI_NAMEREQD is not set in flags.  The patch below will return
EAI_AGAIN for that, while previously it would return inet_ntop result.

2006-08-28  Jakub Jelinek  <jakub@redhat.com>

	* inet/getnameinfo.c (getnameinfo): For AF_INET, check errno
	only if herrno is NETDB_INTERNAL.  Handle errors other than
	ERANGE outside of the loops, handle TRY_AGAIN.

--- libc/inet/getnameinfo.c.jj	2006-06-21 17:36:38.000000000 +0200
+++ libc/inet/getnameinfo.c	2006-08-28 11:47:44.000000000 +0200
@@ -203,48 +203,40 @@ getnameinfo (const struct sockaddr *sa, 
 	if (!(flags & NI_NUMERICHOST))
 	  {
 	    struct hostent *h = NULL;
+	    if (sa->sa_family == AF_INET6)
+	      {
+		while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr),
+					  sizeof(struct in6_addr),
+					  AF_INET6, &th, tmpbuf, tmpbuflen,
+					  &h, &herrno))
+		  if (herrno == NETDB_INTERNAL && errno == ERANGE)
+		    tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+		  else
+		    break;
+	      }
+	    else
+	      {
+		while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
+					  sizeof(struct in_addr), AF_INET,
+					  &th, tmpbuf, tmpbuflen,
+					  &h, &herrno))
+		  if (herrno == NETDB_INTERNAL && errno == ERANGE)
+		    tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+		  else
+		    break;
+	      }
+
 	    if (h == NULL)
 	      {
-		if (sa->sa_family == AF_INET6)
+		if (herrno == NETDB_INTERNAL)
 		  {
-		    while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr),
-					      sizeof(struct in6_addr),
-					      AF_INET6, &th, tmpbuf, tmpbuflen,
-					      &h, &herrno))
-		      {
-			if (herrno == NETDB_INTERNAL)
-			  {
-			    if (errno == ERANGE)
-			      tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
-						      2 * tmpbuflen);
-			    else
-			      {
-				__set_h_errno (herrno);
-				__set_errno (serrno);
-				return EAI_SYSTEM;
-			      }
-			  }
-			else
-			  {
-			    break;
-			  }
-		      }
+		    __set_h_errno (herrno);
+		    return EAI_SYSTEM;
 		  }
-		else
+		if (herrno == TRY_AGAIN)
 		  {
-		    while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
-					      sizeof(struct in_addr), AF_INET,
-					      &th, tmpbuf, tmpbuflen,
-					      &h, &herrno))
-		      {
-			if (errno == ERANGE)
-			  tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
-						  2 * tmpbuflen);
-			else
-			  {
-			    break;
-			  }
-		      }
+		    __set_h_errno (herrno);
+		    return EAI_AGAIN;
 		  }
 	      }
 
@@ -361,10 +353,7 @@ getnameinfo (const struct sockaddr *sa, 
 				 (const void *) &(((const struct sockaddr_in *) sa)->sin_addr),
 				 host, hostlen);
 		if (c == NULL)
-		  {
-		    __set_errno (serrno);
-		    return EAI_SYSTEM;
-		  }
+		  return EAI_SYSTEM;
 	      }
 	    ok = 1;
 	  }

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] getnameinfo fixes
  2006-08-28 10:09 [PATCH] getnameinfo fixes Jakub Jelinek
@ 2006-08-28 16:24 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2006-08-28 16:24 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Applied.


> What I'm not 100% sure is what should we do in the herrno == TRY_AGAIN
> case, when NI_NAMEREQD is not set in flags.  The patch below will return
> EAI_AGAIN for that, while previously it would return inet_ntop result.

Seems to be the right way.  Otherwise there would be no indication that
there might be indeed a better name available.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-08-28 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-28 10:09 [PATCH] getnameinfo fixes Jakub Jelinek
2006-08-28 16:24 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).