From: Mark Stapp Date: Wed, 14 Apr 2021 13:57:41 +0000 (-0400) Subject: nhrpd: fix coverity warning about os_socket() X-Git-Tag: base_8.0~138^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f5a1fb4f321d660ae213255887f0a449c91babd1;p=matthieu%2Ffrr.git 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 --- diff --git a/nhrpd/linux.c b/nhrpd/linux.c index bcf97f030a..f697311d49 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;