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

Bug#309774: [patch] sysdeps/posix/getaddrinfo.c incorrectly checks for sa_len



Package: glibc
Version: 2.3.5-1
Severity: normal
Tags: experimental,patch

Hi,

Neal Walfield has reported the following problem to libc-alpha
(http://sources.redhat.com/ml/libc-alpha/2005-05/msg00044.html):

> sysdeps/posix/getaddrinfo.c incorrectly checks for sa_len.  It should
> check if _HAVE_SA_LEN is defined, not if SALEN is true as is done in,
> for example, sysdeps/generic/ifreq.h .
>
> I encountered this while debugging the Orbit2 test suite on the Hurd.
> It checks if two addresses are the same using the following idiom:
>
>   const struct sockaddr *saddr;
>   struct addrinfo hints, *result = NULL;
>   ...
>   getaddrinfo(link_get_local_hostname(), NULL, &hints, &local _addr) != 0)
>   ...
>   if (af == AF_INET) {
> 	if (!memcmp ((struct sockaddr_in *)result->ai_addr,
>		     (struct sockaddr_in *)saddr,
>                    result->ai_addrlen))

He provided a patch (attached as .dpatch) which got applied by Roland
McGrath on the trunk today.  Neal punted the decision whether to file
this in bugzilla in order to get it fixed for the 2.3 branch to me, so I
am asking here what you guys prefer.


thanks,

Michael

-- 
Michael Banck
Debian Developer
mbanck@debian.org
http://www.advogato.org/person/mbanck/diary.html
#! /bin/sh -e

# All lines beginning with `# DP:' are a description of the patch.
# DP: Description: Fix sa_len checking
# DP: Related bugs:
# DP: Dpatch author: Michael Banck <mbanck@debian.org>
# DP: Patch author: Neal Walfield <neal@gnu.org>
# DP: Upstream status: In CVS
# DP: Status Details: Fixed in trunk, fix in branch possible if 
# DP:                 requested through upstream bugzilla
# DP: Date: 2005-05-18

PATCHLEVEL=0

if [ $# -ne 2 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch) patch -d "$2" -f --no-backup-if-mismatch -p$PATCHLEVEL < $0;;
    -unpatch) patch -d "$2" -f --no-backup-if-mismatch -R -p$PATCHLEVEL < $0;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0


2005-05-17  Neal H. Walfield  <neal@gnu.org>

	* sysdeps/posix/getaddrinfo.c (gaih_local): Check if _HAVE_SA_LEN
	is defined, not if SALEN.
	(gaih_inet): Likewise.

--- ./sysdeps/posix/getaddrinfo.c.orig	2005-05-17 12:16:21.000000000 +0100
+++ ./sysdeps/posix/getaddrinfo.c	2005-05-17 12:30:13.000000000 +0100
@@ -193,10 +193,10 @@ gaih_local (const char *name, const stru
   (*pai)->ai_addrlen = sizeof (struct sockaddr_un);
   (*pai)->ai_addr = (void *) (*pai) + sizeof (struct addrinfo);
 
-#if SALEN
+#ifdef _HAVE_SA_LEN
   ((struct sockaddr_un *) (*pai)->ai_addr)->sun_len =
     sizeof (struct sockaddr_un);
-#endif /* SALEN */
+#endif /* _HAVE_SA_LEN */
 
   ((struct sockaddr_un *)(*pai)->ai_addr)->sun_family = AF_LOCAL;
   memset(((struct sockaddr_un *)(*pai)->ai_addr)->sun_path, 0, UNIX_PATH_MAX);
@@ -859,9 +859,9 @@ gaih_inet (const char *name, const struc
 	    (*pai)->ai_canonname = canon;
 	    canon = NULL;
 
-#if SALEN
+#ifdef _HAVE_SA_LEN
 	    (*pai)->ai_addr->sa_len = socklen;
-#endif /* SALEN */
+#endif /* _HAVE_SA_LEN */
 	    (*pai)->ai_addr->sa_family = family;
 
 	    if (family == AF_INET6)


Reply to: