From b8c1050886081df207fb30f16884c844e7e17fd9 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 25 Sep 2003 16:09:07 +0000 Subject: Make sure that res->ai_canonname is non-NULL and that it doesn't match the 2003-09-25 Jeffrey Stedfast * e-host-utils.c (e_gethostbyaddr_r): Make sure that res->ai_canonname is non-NULL and that it doesn't match the numeric host address that we were trying to resolve. Fixes the second half of bug #46006. svn path=/trunk/; revision=22701 --- e-util/ChangeLog | 12 ++++++++++++ e-util/e-host-utils.c | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 21014249b5..38ee4c5d26 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,15 @@ +2003-09-25 Jeffrey Stedfast + + * e-host-utils.c (e_gethostbyaddr_r): Make sure that + res->ai_canonname is non-NULL and that it doesn't match the + numeric host address that we were trying to resolve. Fixes the + second half of bug #46006. + +2003-09-19 Jeffrey Stedfast + + * e-host-utils.c (e_gethostbyaddr_r): Work around a bug in glibc + 2.3.2's gethostbyaddr_r() implementation. + 2003-09-11 Dan Winship * Makefile.am (noinst_LTLIBRARIES): Remove libeutil-static.la and diff --git a/e-util/e-host-utils.c b/e-util/e-host-utils.c index e1a7296b3d..1d685019cc 100644 --- a/e-util/e-host-utils.c +++ b/e-util/e-host-utils.c @@ -313,6 +313,19 @@ e_gethostbyaddr_r (const char *addr, int addrlen, int type, struct hostent *host return -1; } + /* If nodename is not null, and if requested by the AI_CANONNAME flag, the ai_canonname + * field of the first returned addrinfo structure shall point to a null-terminated + * string containing the canonical name corresponding to the input nodename; if the + * canonical name is not available, then ai_canonname shall refer to the nodename + * argument or a string with the same contents. + * + * Note: NetBSD seems to set res->ai_canonname to NULL in this case instead. + */ + if (!res->ai_canonname || !strcmp (res->ai_canonname, name)) { + *herr = HOST_NOT_FOUND; + return -1; + } + len = ALIGN (strlen (res->ai_canonname) + 1); if (buflen < IPv6_BUFLEN_MIN + len + res->ai_addrlen + sizeof (char *)) return ERANGE; @@ -363,8 +376,20 @@ e_gethostbyaddr_r (const char *addr, int addrlen, int type, struct hostent *host int retval; retval = gethostbyaddr_r (addr, addrlen, type, host, buf, buflen, &hp, herr); - if (hp != NULL) + if (hp != NULL) { *herr = 0; + retval = 0; + } else if (retval == 0) { + /* glibc 2.3.2 workaround - it seems that + * gethostbyaddr_r will sometimes return 0 on fail and + * fill @host with garbage strings from /etc/hosts + * (failure to parse the file? who knows). Luckily, it + * seems that we can rely on @hp being NULL on + * fail. + */ + retval = -1; + } + return retval; #endif #else /* No support for gethostbyaddr_r */ -- cgit v1.2.3