From: Roy Marples Date: Sat, 30 May 2020 10:36:20 +0000 (+0000) Subject: Fix some Coverity isues X-Git-Tag: v9.1.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd4f6fc05be710f096fbff9532459cb1730981da;p=thirdparty%2Fdhcpcd.git Fix some Coverity isues --- diff --git a/src/common.c b/src/common.c index 2586c41c..c60d9846 100644 --- a/src/common.c +++ b/src/common.c @@ -46,7 +46,7 @@ hwaddr_ntoa(const void *hwaddr, size_t hwlen, char *buf, size_t buflen) const unsigned char *hp, *ep; char *p; - if (buf == NULL) + if (buf == NULL || hwlen == 0) return NULL; if (hwlen * 3 > buflen) { diff --git a/src/dhcp6.c b/src/dhcp6.c index a24277c3..84c4b41e 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -3743,13 +3743,17 @@ dhcp6_openraw(void) v = 1; if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &v, sizeof(v)) == -1) - return -1; + goto errexit; v = offsetof(struct udphdr, uh_sum); if (setsockopt(fd, IPPROTO_IPV6, IPV6_CHECKSUM, &v, sizeof(v)) == -1) - return -1; + goto errexit; return fd; + +errexit: + close(fd); + return -1; } int diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 0842e6d0..182b2989 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -358,7 +358,7 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) /* Don't use loginfo because this makes no sense in a log. */ if (!(loggetopts() & LOGERR_QUIET)) - fprintf(stderr, "forked to background, child pid %d\n", + (void)fprintf(stderr, "forked to background, child pid %d\n", getpid()); i = EXIT_SUCCESS; if (write(ctx->fork_fd, &i, sizeof(i)) == -1) diff --git a/src/if-linux.c b/src/if-linux.c index 42eeec24..348db0e6 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -2046,8 +2046,8 @@ ip6_forwarding(const char *ifname) return 0; i = (int)strtoi(buf, NULL, 0, INT_MIN, INT_MAX, &error); if (error != 0) - return -1; - return error != 0 ? 0 : i; + return 0; + return i; } #endif /* INET6 */ diff --git a/src/privsep.c b/src/privsep.c index 8e8325bf..ce4f0565 100644 --- a/src/privsep.c +++ b/src/privsep.c @@ -248,7 +248,7 @@ ps_dostart(struct dhcpcd_ctx *ctx, errexit: /* Failure to start root or inet processes is fatal. */ if (priv_fd == &ctx->ps_root_fd || priv_fd == &ctx->ps_inet_fd) - ps_sendcmd(ctx, *priv_fd, PS_STOP, 0, NULL, 0); + (void)ps_sendcmd(ctx, *priv_fd, PS_STOP, 0, NULL, 0); shutdown(*priv_fd, SHUT_RDWR); *priv_fd = -1; return -1;