summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Ferguson <nathaniel@leapfrog.foundation>2020-05-03 03:13:25 -0400
committerTobias Klauser <tklauser@distanz.ch>2020-05-04 14:09:23 +0200
commita8c3c53c271b21878ea7c1c083bb5abfd634bb41 (patch)
tree66c50e4e2e1fb3f25f01a03b75c2e3189753b04f
parent9d71c0f9341711c5b0094bf95d087251689112a4 (diff)
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 <nathaniel@leapfrog.foundation> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--proto_lldp.c14
1 files 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: