summaryrefslogtreecommitdiffstats
path: root/ldpd/util.c
diff options
context:
space:
mode:
authorF. Aragon <paco@voltanet.io>2018-07-03 20:07:25 +0200
committerF. Aragon <paco@voltanet.io>2018-07-04 00:01:22 +0200
commit4149ef7c0f0876a2b9fdfe34afc1ecd9036b2382 (patch)
tree22341ea9b9bcd5bb71483cf5559f7906233690d5 /ldpd/util.c
parentMerge pull request #2619 from pguibert6WIND/show_ipv6_bgp_wrong (diff)
downloadfrr-4149ef7c0f0876a2b9fdfe34afc1ecd9036b2382.tar.xz
frr-4149ef7c0f0876a2b9fdfe34afc1ecd9036b2382.zip
ldpd: buffer underflow, thread safety (PVS-Studio)
This commit fixes two issues: - memcpy() using containers of different sizes when using addr2sa(), mixing 'struct sockaddr_storage' and 'union sockunion'. - addr2sa() function not being thread safe (using a local static variable as container. Signed-off-by: F. Aragon <paco@voltanet.io>
Diffstat (limited to '')
-rw-r--r--ldpd/util.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/ldpd/util.c b/ldpd/util.c
index e735263f5..12f9cb0cc 100644
--- a/ldpd/util.c
+++ b/ldpd/util.c
@@ -305,14 +305,13 @@ clearscope(struct in6_addr *in6)
}
}
-struct sockaddr *
-addr2sa(int af, union ldpd_addr *addr, uint16_t port)
+void
+addr2sa(int af, const union ldpd_addr *addr, uint16_t port, union sockunion *su)
{
- static struct sockaddr_storage ss;
- struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss;
- struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&ss;
+ struct sockaddr_in *sa_in = &su->sin;
+ struct sockaddr_in6 *sa_in6 = &su->sin6;
- memset(&ss, 0, sizeof(ss));
+ memset(su, 0, sizeof(*su));
switch (af) {
case AF_INET:
sa_in->sin_family = AF_INET;
@@ -333,8 +332,6 @@ addr2sa(int af, union ldpd_addr *addr, uint16_t port)
default:
fatalx("addr2sa: unknown af");
}
-
- return ((struct sockaddr *)&ss);
}
void