@matheusbsbs / matheus-bagliano / commits / 3aff874af2
Fork 0

daemon.c: avoid accessing ss_family member of struct sockaddr_storage

When NO_SOCKADDR_STORAGE is set for a platform, either sockaddr_in or sockaddr_in6 is used intead. Neither of which has an ss_family member. They have an sin_family and sin6_family member respectively. Since the addrcmp() function accesses the ss_family member of a sockaddr_storage struct, compilation fails on platforms which define NO_SOCKADDR_STORAGE. Since any sockaddr_* structure can be cast to a struct sockaddr and have its sa_family member read, do so here to workaround this issue. Thanks to Martin Storsjö for pointing out the fix, and Gary Vaughan for drawing attention to the issue. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Mar 15, 2010 at 17:10 UTC 3aff874af239965ea78c37d14266d6c2233ad431
1 file changed +7 -4
daemon.c
+7 -4
@@ -590,14 +590,17 @@ static int execute(struct sockaddr *addr)
590 static int addrcmp(const struct sockaddr_storage *s1,
591 const struct sockaddr_storage *s2)
592 {
593 - if (s1->ss_family != s2->ss_family)
594 - return s1->ss_family - s2->ss_family;
595 - if (s1->ss_family == AF_INET)
593 + const struct sockaddr *sa1 = (const struct sockaddr*) s1;
594 + const struct sockaddr *sa2 = (const struct sockaddr*) s2;
595 +
596 + if (sa1->sa_family != sa2->sa_family)
597 + return sa1->sa_family - sa2->sa_family;
598 + if (sa1->sa_family == AF_INET)
599 return memcmp(&((struct sockaddr_in *)s1)->sin_addr,
600 &((struct sockaddr_in *)s2)->sin_addr,
601 sizeof(struct in_addr));
602 #ifndef NO_IPV6
600 - if (s1->ss_family == AF_INET6)
603 + if (sa1->sa_family == AF_INET6)
604 return memcmp(&((struct sockaddr_in6 *)s1)->sin6_addr,
605 &((struct sockaddr_in6 *)s2)->sin6_addr,
606 sizeof(struct in6_addr));