From a8c3c53c271b21878ea7c1c083bb5abfd634bb41 Mon Sep 17 00:00:00 2001 From: Nathaniel Ferguson Date: Sun, 3 May 2020 03:13:25 -0400 Subject: proto_lldp: Check inet_ntop() return values Make netsniff error out of a recv routine if calls to inet_ntop() fail by adding return value checks. There are other inet_ntop() usages of similar however these are in a receive code path with user data for most of the variables Signed-off-by: Nathaniel Ferguson Signed-off-by: Tobias Klauser --- proto_lldp.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/proto_lldp.c b/proto_lldp.c index 4f71ec6..1640d19 100644 --- a/proto_lldp.c +++ b/proto_lldp.c @@ -88,7 +88,7 @@ static int lldp_print_net_addr(const uint8_t *addr, size_t addrlen) { uint8_t af; - char buf[64]; + char buf[64] = {0}; if (addrlen < 1) return -EINVAL; @@ -99,13 +99,21 @@ static int lldp_print_net_addr(const uint8_t *addr, size_t addrlen) case IANA_AF_IPV4: if (addrlen < 4) return -EINVAL; - inet_ntop(AF_INET, addr, buf, sizeof(buf)); + if (inet_ntop(AF_INET, addr, buf, sizeof(buf)) == NULL) { + tprintf("[MALFORMED ADDR]"); + return 0; + } + tprintf("%s", buf); break; case IANA_AF_IPV6: if (addrlen < 16) return -EINVAL; - inet_ntop(AF_INET6, addr, buf, sizeof(buf)); + if (inet_ntop(AF_INET6, addr, buf, sizeof(buf)) == NULL) { + tprintf("[MALFORMED ADDR]"); + return 0; + } + tprintf("%s", buf); break; case IANA_AF_802: -- cgit v1.2.3-54-g00ecf