From 22ed4467a413961816f317c641e436ca627d06d2 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 5 Apr 2022 07:10:30 +0200 Subject: treewide: Unchecked return value from library, CWE-252 All instances were harmless, but it might be useful to have some debug messages here and there. Reported by Coverity. Signed-off-by: Stefano Brivio --- util.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 81cf744..c3475d6 100644 --- a/util.c +++ b/util.c @@ -154,7 +154,8 @@ void passt_vsyslog(int pri, const char *format, va_list ap) if (log_opt & LOG_PERROR) fprintf(stderr, "%s", buf + sizeof("<0>")); - send(log_sock, buf, n, 0); + if (send(log_sock, buf, n, 0) != n) + fprintf(stderr, "Failed to send %i bytes to syslog\n", n); } #define IPV6_NH_OPT(nh) \ @@ -239,7 +240,7 @@ int sock_l4(const struct ctx *c, int af, uint8_t proto, uint16_t port, }; const struct sockaddr *sa; struct epoll_event ev; - int fd, sl, one = 1; + int fd, sl, y = 1; if (proto != IPPROTO_TCP && proto != IPPROTO_UDP && proto != IPPROTO_ICMP && proto != IPPROTO_ICMPV6) @@ -287,10 +288,12 @@ int sock_l4(const struct ctx *c, int af, uint8_t proto, uint16_t port, sa = (const struct sockaddr *)&addr6; sl = sizeof(addr6); - setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one)); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &y, sizeof(y))) + debug("Failed to set IPV6_V6ONLY on socket %i", fd); } - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &y, sizeof(y))) + debug("Failed to set IPV6_V6ONLY on socket %i", fd); if (bind(fd, sa, sl) < 0) { /* We'll fail to bind to low ports if we don't have enough -- cgit v1.2.3