Fix Coverity warning in sk_interface_addr().

Copy the address directly to struct sockaddr_in or sockaddr_in6 instead
of sockaddr as Coverity doesn't seem to understand the union and reports
a buffer overflow.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2014-09-17 11:11:16 +02:00 committed by Richard Cochran
parent 9ddd2a6024
commit 6b459abc8c
1 changed files with 2 additions and 1 deletions

3
sk.c
View File

@ -191,14 +191,15 @@ int sk_interface_addr(const char *name, int family, struct address *addr)
switch (family) { switch (family) {
case AF_INET: case AF_INET:
addr->len = sizeof(addr->sin); addr->len = sizeof(addr->sin);
memcpy(&addr->sin, i->ifa_addr, addr->len);
break; break;
case AF_INET6: case AF_INET6:
addr->len = sizeof(addr->sin6); addr->len = sizeof(addr->sin6);
memcpy(&addr->sin6, i->ifa_addr, addr->len);
break; break;
default: default:
continue; continue;
} }
memcpy(&addr->sa, i->ifa_addr, addr->len);
result = 0; result = 0;
break; break;
} }