From f5a1fb4f321d660ae213255887f0a449c91babd1 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 14 Apr 2021 09:57:41 -0400 Subject: nhrpd: fix coverity warning about os_socket() Ensure we don't try to use an invalid fd in nhrpd, reported by coverity. Signed-off-by: Mark Stapp --- nhrpd/linux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nhrpd/linux.c') diff --git a/nhrpd/linux.c b/nhrpd/linux.c index bcf97f030..f697311d4 100644 --- a/nhrpd/linux.c +++ b/nhrpd/linux.c @@ -60,7 +60,7 @@ int os_sendmsg(const uint8_t *buf, size_t len, int ifindex, const uint8_t *addr, .msg_iov = &iov, .msg_iovlen = 1, }; - int status; + int status, fd; if (addrlen > sizeof(lladdr.sll_addr)) return -1; @@ -72,7 +72,11 @@ int os_sendmsg(const uint8_t *buf, size_t len, int ifindex, const uint8_t *addr, lladdr.sll_halen = addrlen; memcpy(lladdr.sll_addr, addr, addrlen); - status = sendmsg(os_socket(), &msg, 0); + fd = os_socket(); + if (fd < 0) + return -1; + + status = sendmsg(fd, &msg, 0); if (status < 0) return -errno; -- cgit v1.2.3