From: Roy Marples Date: Wed, 12 Feb 2014 20:51:57 +0000 (+0000) Subject: Ensure we close the contol socket if we fail to connect. X-Git-Tag: v6.3.0~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2433e54dc8af1bc7c199e0a776a71c6cedd1e10b;p=thirdparty%2Fdhcpcd.git Ensure we close the contol socket if we fail to connect. Don't crash when closing IPv6ND or DHCPv6 when not the IPv6 protocol is not started. --- diff --git a/control.c b/control.c index 6e47d63a..14d07b2c 100644 --- a/control.c +++ b/control.c @@ -197,7 +197,12 @@ control_open(struct dhcpcd_ctx *ctx) if ((len = make_sock(ctx, &sun)) == -1) return -1; - return connect(ctx->control_fd, (struct sockaddr *)&sun, len); + if (connect(ctx->control_fd, (struct sockaddr *)&sun, len) == -1) { + close(ctx->control_fd); + ctx->control_fd = -1; + return -1; + } + return 0; } int diff --git a/dhcp6.c b/dhcp6.c index 6dcd5ef3..57add6af 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -2670,7 +2670,7 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) break; } } - if (ifp == NULL) { + if (ifp == NULL && ctx->ipv6) { if (ctx->ipv6->dhcp_fd != -1) { eloop_event_delete(ctx->eloop, ctx->ipv6->dhcp_fd); close(ctx->ipv6->dhcp_fd); diff --git a/dhcpcd.c b/dhcpcd.c index e8d413f1..714974c2 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1503,5 +1503,6 @@ exit1: if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED)) syslog(LOG_INFO, "exited"); + closelog(); return i; } diff --git a/ipv6nd.c b/ipv6nd.c index 8b8f52fa..acc2699f 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -999,9 +999,11 @@ ipv6nd_has_ra(const struct interface *ifp) { const struct ra *rap; - TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) - if (rap->iface == ifp) - return 1; + if (ifp->ctx->ipv6) { + TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) + if (rap->iface == ifp) + return 1; + } return 0; } @@ -1227,6 +1229,9 @@ ipv6nd_drop(struct interface *ifp) int expired = 0; TAILQ_HEAD(rahead, ra) rtrs; + if (ifp->ctx->ipv6 == NULL) + return; + eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); TAILQ_INIT(&rtrs); TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {