krb5 commit: Avoid using length fields in socket addresses
Greg Hudson
ghudson at MIT.EDU
Fri Jul 4 15:21:22 EDT 2014
https://github.com/krb5/krb5/commit/48a0b16ab1f70b6486a6d7af7ca9e7b376b19956
commit 48a0b16ab1f70b6486a6d7af7ca9e7b376b19956
Author: Greg Hudson <ghudson at mit.edu>
Date: Thu Jul 3 12:48:53 2014 -0400
Avoid using length fields in socket addresses
Remove code to set or reference the length fields of socket addresses
(sa_len/sin_len/sin6_len), since they aren't portable and setting them
is not required. Remove autoconf tests for those fields which are no
longer used or which were never used.
There is one exception: in localaddr.c, we still neeed to reference
sa_len for the definition of ifreq_size on platforms which have
sa_len. Leave that behind, along with the autoconf test which defines
SA_LEN.
src/clients/klist/klist.c | 6 ------
src/configure.in | 12 ------------
src/lib/apputils/net-server.c | 18 ------------------
src/lib/krb5/os/localaddr.c | 12 ------------
src/lib/rpc/clnt_generic.c | 3 ---
src/lib/rpc/clnt_simple.c | 3 ---
src/lib/rpc/getrpcport.c | 3 ---
src/lib/rpc/svc_tcp.c | 3 ---
src/lib/rpc/svc_udp.c | 3 ---
src/tests/resolve/addrinfo-test.c | 6 ------
src/util/support/fake-addrinfo.c | 9 ---------
11 files changed, 0 insertions(+), 78 deletions(-)
diff --git a/src/clients/klist/klist.c b/src/clients/klist/klist.c
index 9388d14..51eaa07 100644
--- a/src/clients/klist/klist.c
+++ b/src/clients/klist/klist.c
@@ -822,9 +822,6 @@ void one_addr(a)
{
struct sockaddr_in *sinp = ss2sin (&ss);
sinp->sin_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sinp->sin_len = sizeof (struct sockaddr_in);
-#endif
memcpy (&sinp->sin_addr, a->contents, 4);
}
break;
@@ -834,9 +831,6 @@ void one_addr(a)
{
struct sockaddr_in6 *sin6p = ss2sin6 (&ss);
sin6p->sin6_family = AF_INET6;
-#ifdef HAVE_SA_LEN
- sin6p->sin6_len = sizeof (struct sockaddr_in6);
-#endif
memcpy (&sin6p->sin6_addr, a->contents, 16);
}
break;
diff --git a/src/configure.in b/src/configure.in
index 39e3738..1339379 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -402,9 +402,6 @@ AC_CHECK_HEADER(regexp.h, [], [],
#define RETURN(c) return(c)
#define ERROR(c)
])
-AC_CHECK_MEMBERS([struct sockaddr_in.sin_len, struct sockaddr.sa_len], , ,
- [#include <sys/types.h>
-#include <netinet/in.h>])
AC_CHECK_MEMBERS([struct stat.st_mtimensec,struct stat.st_mtimespec.tv_nsec,struct stat.st_mtim.tv_nsec],,,[#include <sys/types.h>
#include <sys/stat.h>])
KRB5_AC_REGEX_FUNCS
@@ -1003,15 +1000,6 @@ else
fi
AC_SUBST(GSSRPC__BSD_TYPEALIASES)
-# sockaddr length field checks
-
-AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , ,
- [#include <sys/types.h>
-@%:@include <netinet/in.h>])
-AC_CHECK_MEMBERS([struct sockaddr.sa_len], , ,
- [#include <sys/types.h>
-@%:@include <sys/socket.h>])
-
AC_MSG_CHECKING([return type of setrpcent])
AC_CACHE_VAL(k5_cv_type_setrpcent,
[AC_TRY_COMPILE([#include <netdb.h>
diff --git a/src/lib/apputils/net-server.c b/src/lib/apputils/net-server.c
index 558eee3..1ad6414 100644
--- a/src/lib/apputils/net-server.c
+++ b/src/lib/apputils/net-server.c
@@ -708,16 +708,10 @@ setup_tcp_listener_ports(struct socksetup *data)
memset(&sin4, 0, sizeof(sin4));
sin4.sin_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sin4.sin_len = sizeof(sin4);
-#endif
sin4.sin_addr.s_addr = INADDR_ANY;
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
-#ifdef SIN6_LEN
- sin6.sin6_len = sizeof(sin6);
-#endif
sin6.sin6_addr = in6addr_any;
FOREACH_ELT (tcp_port_data, i, port) {
@@ -776,16 +770,10 @@ setup_rpc_listener_ports(struct socksetup *data)
memset(&sin4, 0, sizeof(sin4));
sin4.sin_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sin4.sin_len = sizeof(sin4);
-#endif
sin4.sin_addr.s_addr = INADDR_ANY;
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
-#ifdef HAVE_SA_LEN
- sin6.sin6_len = sizeof(sin6);
-#endif
sin6.sin6_addr = in6addr_any;
FOREACH_ELT (rpc_svc_data, i, svc) {
@@ -846,9 +834,6 @@ setup_udp_pktinfo_ports(struct socksetup *data)
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sa.sin_len = sizeof(sa);
-#endif
r = setup_udp_port_1(data, (struct sockaddr *)&sa, 4);
if (r == 0)
data->do_ipv4_udp_all = FALSE;
@@ -861,9 +846,6 @@ setup_udp_pktinfo_ports(struct socksetup *data)
memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6;
-#ifdef HAVE_SA_LEN
- sa.sin6_len = sizeof(sa);
-#endif
r = setup_udp_port_1(data, (struct sockaddr *)&sa, 6);
if (r == 0)
data->do_ipv6_udp_all = FALSE;
diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c
index 0e6a05c..9f77652 100644
--- a/src/lib/krb5/os/localaddr.c
+++ b/src/lib/krb5/os/localaddr.c
@@ -243,11 +243,6 @@ addr_eq (const struct sockaddr *s1, const struct sockaddr *s2)
{
if (s1->sa_family != s2->sa_family)
return 0;
-#ifdef HAVE_SA_LEN
- if (s1->sa_len != s2->sa_len)
- return 0;
- return !memcmp (s1, s2, s1->sa_len);
-#else
#define CMPTYPE(T,F) (!memcmp(&((const T*)s1)->F,&((const T*)s2)->F,sizeof(((const T*)s1)->F)))
switch (s1->sa_family) {
case AF_INET:
@@ -258,7 +253,6 @@ addr_eq (const struct sockaddr *s1, const struct sockaddr *s2)
/* Err on side of duplicate listings. */
return 0;
}
-#endif
}
#endif
@@ -1402,9 +1396,6 @@ get_localaddrs (krb5_context context, krb5_address ***addr, int use_profile)
struct sockaddr_in *sinp = ss2sin (&ss);
sinp->sin_family = AF_INET;
addrp = &sinp->sin_addr;
-#ifdef HAVE_SA_LEN
- sinp->sin_len = sizeof (struct sockaddr_in);
-#endif
break;
}
case ADDRTYPE_INET6:
@@ -1412,9 +1403,6 @@ get_localaddrs (krb5_context context, krb5_address ***addr, int use_profile)
struct sockaddr_in6 *sin6p = ss2sin6 (&ss);
sin6p->sin6_family = AF_INET6;
addrp = &sin6p->sin6_addr;
-#ifdef HAVE_SA_LEN
- sin6p->sin6_len = sizeof (struct sockaddr_in6);
-#endif
break;
}
default:
diff --git a/src/lib/rpc/clnt_generic.c b/src/lib/rpc/clnt_generic.c
index e2e5b1a..da3e8e8 100644
--- a/src/lib/rpc/clnt_generic.c
+++ b/src/lib/rpc/clnt_generic.c
@@ -76,9 +76,6 @@ clnt_create(
return (NULL);
}
memset(&sockin, 0, sizeof(sockin));
-#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- sockin.sin_len = sizeof(sockin);
-#endif
sockin.sin_family = h->h_addrtype;
sockin.sin_port = 0;
memmove((char*)&sockin.sin_addr, h->h_addr, sizeof(sockin.sin_addr));
diff --git a/src/lib/rpc/clnt_simple.c b/src/lib/rpc/clnt_simple.c
index c1dc8fe..df8f246 100644
--- a/src/lib/rpc/clnt_simple.c
+++ b/src/lib/rpc/clnt_simple.c
@@ -107,9 +107,6 @@ callrpc(
memset(&server_addr, 0, sizeof(server_addr));
memmove((char *)&server_addr.sin_addr, hp->h_addr,
sizeof(server_addr.sin_addr));
-#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- server_addr.sin_len = sizeof(server_addr);
-#endif
server_addr.sin_family = AF_INET;
server_addr.sin_port = 0;
if ((crp->client = clntudp_create(&server_addr, prognum,
diff --git a/src/lib/rpc/getrpcport.c b/src/lib/rpc/getrpcport.c
index 8247bb3..32ff739 100644
--- a/src/lib/rpc/getrpcport.c
+++ b/src/lib/rpc/getrpcport.c
@@ -54,9 +54,6 @@ gssrpc_getrpcport(
return (0);
memset(&addr, 0, sizeof(addr));
memmove((char *) &addr.sin_addr, hp->h_addr, sizeof(addr.sin_addr));
-#if HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- addr.sin_len = sizeof(addr);
-#endif
addr.sin_family = AF_INET;
addr.sin_port = 0;
return (pmap_getport(&addr, prognum, versnum, proto));
diff --git a/src/lib/rpc/svc_tcp.c b/src/lib/rpc/svc_tcp.c
index 3d02164..f052203 100644
--- a/src/lib/rpc/svc_tcp.c
+++ b/src/lib/rpc/svc_tcp.c
@@ -161,9 +161,6 @@ svctcp_create(
madesock = TRUE;
memset(&ss, 0, sizeof(ss));
sa->sa_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sa->sa_len = sizeof(struct sockaddr_in);
-#endif
} else {
len = sizeof(struct sockaddr_storage);
if (getsockname(sock, sa, &len) != 0) {
diff --git a/src/lib/rpc/svc_udp.c b/src/lib/rpc/svc_udp.c
index 603f56a..9280061 100644
--- a/src/lib/rpc/svc_udp.c
+++ b/src/lib/rpc/svc_udp.c
@@ -132,9 +132,6 @@ svcudp_bufcreate(
madesock = TRUE;
memset(&ss, 0, sizeof(ss));
sa->sa_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sa->sa_len = sizeof(struct sockaddr_in);
-#endif
} else {
len = sizeof(struct sockaddr_storage);
if (getsockname(sock, sa, &len) < 0) {
diff --git a/src/tests/resolve/addrinfo-test.c b/src/tests/resolve/addrinfo-test.c
index d53b48a..b5c6da9 100644
--- a/src/tests/resolve/addrinfo-test.c
+++ b/src/tests/resolve/addrinfo-test.c
@@ -266,12 +266,6 @@ int main (int argc, char *argv[])
return 1;
}
-#if defined(SIN6_LEN)
- if (ap->ai_addr->sa_len == 0)
- printf ("BAD: sa_len not set!\n");
-#endif
-
-
for (ap2 = ap; ap2; ap2 = ap2->ai_next) {
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
/* If we don't do this, even AIX's own getnameinfo will reject
diff --git a/src/util/support/fake-addrinfo.c b/src/util/support/fake-addrinfo.c
index 6ddf859..4824a61 100644
--- a/src/util/support/fake-addrinfo.c
+++ b/src/util/support/fake-addrinfo.c
@@ -566,9 +566,6 @@ static inline int fai_add_entry (struct addrinfo **result, void *addr,
sin4->sin_family = AF_INET;
sin4->sin_addr = *(struct in_addr *)addr;
sin4->sin_port = port;
-#ifdef HAVE_SA_LEN
- sin4->sin_len = sizeof (struct sockaddr_in);
-#endif
}
if (template->ai_family == AF_INET6) {
struct sockaddr_in6 *sin6;
@@ -580,9 +577,6 @@ static inline int fai_add_entry (struct addrinfo **result, void *addr,
sin6->sin6_family = AF_INET6;
sin6->sin6_addr = *(struct in6_addr *)addr;
sin6->sin6_port = port;
-#ifdef HAVE_SA_LEN
- sin6->sin6_len = sizeof (struct sockaddr_in6);
-#endif
}
n->ai_next = *result;
*result = n;
@@ -1294,9 +1288,6 @@ getaddrinfo (const char *name, const char *serv, const struct addrinfo *hint,
just leftover from previous contents of the memory
block?). So, always override what libc returned. */
ai->ai_addr->sa_family = ai->ai_family;
-#ifdef HAVE_SA_LEN /* always true on AIX, actually */
- ai->ai_addr->sa_len = ai->ai_addrlen;
-#endif
}
#endif
More information about the cvs-krb5
mailing list