} else {
free(state->token);
state->token = NULL;
+ return NULL;
}
- if (t->realm) {
+ if (t->realm_len) {
state->token->realm = malloc(t->realm_len);
if (state->token->realm) {
state->token->realm_len = t->realm_len;
memcpy(state->token->realm, t->realm,
t->realm_len);
- } else {
+ } else {
free(state->token->key);
free(state->token);
state->token = NULL;
- }
+ return NULL;
+ }
} else {
state->token->realm = NULL;
state->token->realm_len = 0;
return dl - (dl % ADDR6SZ);
}
- sz = 0;
if (opt->type & (UINT32 | ADDRIPV4))
sz = sizeof(uint32_t);
else if (opt->type & UINT16)
if (o == opt) {
if (op) {
if (!ctx->opt_buffer) {
- ctx->opt_buffer = malloc(sizeof(*dhcp));
+ ctx->opt_buffer =
+ malloc(DHCP_OPTION_LEN +
+ BOOTFILE_LEN + SERVERNAME_LEN);
if (ctx->opt_buffer == NULL)
return NULL;
}
write_lease(const struct interface *ifp, const struct dhcp_message *dhcp)
{
int fd;
- ssize_t bytes = sizeof(*dhcp);
- const uint8_t *p = dhcp->options;
- const uint8_t *e = p + sizeof(dhcp->options);
+ ssize_t bytes;
+ const uint8_t *e, *p;
uint8_t l;
uint8_t o = 0;
const struct dhcp_state *state = D_CSTATE(ifp);
return -1;
/* Only write as much as we need */
+ p = dhcp->options;
+ e = p + sizeof(dhcp->options);
+ bytes = sizeof(*dhcp);
while (p < e) {
o = *p;
if (o == DHO_END) {
/* Set the outbound interface */
cm = CMSG_FIRSTHDR(&ctx->sndhdr);
+ if (cm == NULL) /* unlikely */
+ return -1;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(pi));
p += sizeof(u8);
len = u8;
memcpy(&prefix.s6_addr, p, sizeof(prefix.s6_addr));
- p += sizeof(prefix.s6_addr);
TAILQ_FOREACH(a, &state->addrs, next) {
if (IN6_ARE_ADDR_EQUAL(&a->prefix, &prefix))
{
struct dhcp6_state *state;
struct dhcpcd_ctx *ctx;
+ int options;
eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
+ if (ifp->options)
+ options = ifp->options->options;
+ else
+ options = 0;
/*
* As the interface is going away from dhcpcd we need to
* remove the delegated addresses, otherwise we lose track
* how we remember which interface delegated.
*
* XXX The below is no longer true due to the change of the
- * default IAID, but do PPP links have stable ethernet addresses?
+ * default IAID, but do PPP links have stable ethernet
+ * addresses?
*
* To make it more interesting, on some OS's with PPP links
* there is no guarantee the delegating interface will have
* the same name or index so think very hard before changing
* this.
*/
- if (ifp->options &&
- ifp->options->options & (DHCPCD_STOPPING | DHCPCD_RELEASE) &&
- (ifp->options->options & (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
+ if (options & (DHCPCD_STOPPING | DHCPCD_RELEASE) &&
+ (options &
+ (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
(DHCPCD_EXITING | DHCPCD_PERSISTENT))
dhcp6_delete_delegates(ifp);
state = D6_STATE(ifp);
if (state) {
dhcp_auth_reset(&state->auth);
- if (ifp->options->options & DHCPCD_RELEASE) {
+ if (options & DHCPCD_RELEASE) {
if (ifp->carrier != LINK_DOWN)
dhcp6_startrelease(ifp);
unlink(state->leasefile);
}
dhcp6_freedrop_addrs(ifp, drop, NULL);
if (drop && state->new &&
- (ifp->options->options &
+ (options &
(DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
(DHCPCD_EXITING | DHCPCD_PERSISTENT))
{
}
/* If we don't have any more DHCP6 enabled interfaces,
- * close the global socketo and release resources */
+ * close the global socket and release resources */
ctx = ifp->ctx;
if (ctx->ifaces) {
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
}
if (ctx->ifdc) {
for (ctx->ifdc--; ctx->ifdc >= 0; ctx->ifdc--)
- free(ctx->ifdv[ctx->ifac]);
+ free(ctx->ifdv[ctx->ifdc]);
free(ctx->ifdv);
ctx->ifdv = NULL;
}
n = strdup(value);
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
+ free(match);
return NULL;
}
free(lst[i]);
} else {
/* Append a space and the value to it */
l = strlen(lst[i]);
- lv = strlen(p);
+ lv = p ? strlen(p) : 0;
n = realloc(lst[i], l + lv + 2);
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
+ free(match);
return NULL;
}
lst[i] = n;
i++;
}
+ free(match);
n = strdup(value);
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
newlist = realloc(lst, sizeof(char *) * (i + 2));
if (newlist == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
+ free(n);
return NULL;
}
newlist[i] = n;
newlist[i + 1] = NULL;
ifo->environ = newlist;
- free(match);
return newlist[i];
}
nt = strdup(t);
if (nt == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
- return NULL;
+ free(o);
+ return v;
}
- (*argc)++;
- n = realloc(v, sizeof(char *) * ((*argc)));
+ n = realloc(v, sizeof(char *) * ((*argc) + 1));
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
- return NULL;
+ free(o);
+ free(nt);
+ return v;
}
v = n;
- v[(*argc) - 1] = nt;
+ v[(*argc)++] = nt;
}
free(o);
return v;
}
if (p != NULL)
*--p = '/';
- else if (net != NULL)
+ else if (net != NULL && addr != NULL)
net->s_addr = ipv4_getnetmask(addr->s_addr);
return 0;
}
dop = NULL;
dop_len = NULL;
- i = 0;
+ //i = 0;
switch(opt) {
case 'f': /* FALLTHROUGH */
case 'g': /* FALLTHROUGH */
sizeof(**dop) * ((*dop_len) + 1))) == NULL)
{
syslog(LOG_ERR, "%s: %m", __func__);
+ free(np);
return -1;
}
*dop = ndop;
/* Set the outbound interface */
cm = CMSG_FIRSTHDR(&ctx->sndhdr);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(pi));
/* Hop limit */
cm = CMSG_NXTHDR(&ctx->sndhdr, cm);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_HOPLIMIT;
cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));
len -= sizeof(struct nd_router_advert);
p = ((uint8_t *)icp) + sizeof(struct nd_router_advert);
- olen = 0;
lifetime = ~0U;
- for (olen = 0; len > 0; p += olen, len -= olen) {
+ for (; len > 0; p += olen, len -= olen) {
if ((size_t)len < sizeof(struct nd_opt_hdr)) {
syslog(LOG_ERR, "%s: short option", ifp->name);
break;
//memcpy(&dst.sin6_addr, &ap->addr, sizeof(dst.sin6_addr));
dst.sin6_scope_id = ap->iface->index;
- sndhdr.msg_name = (caddr_t)&dst;
- sndhdr.msg_iov[0].iov_base = ap->ns;
- sndhdr.msg_iov[0].iov_len = ap->nslen;
+ ctx = ap->iface->ctx->ipv6;
+ ctx->sndhdr.msg_name = (caddr_t)&dst;
+ ctx->sndhdr.msg_iov[0].iov_base = ap->ns;
+ ctx->sndhdr.msg_iov[0].iov_len = ap->nslen;
/* Set the outbound interface */
- cm = CMSG_FIRSTHDR(&sndhdr);
+ cm = CMSG_FIRSTHDR(&ctx->sndhdr);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(pi));
/* Hop limit */
cm = CMSG_NXTHDR(&sndhdr, cm);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_HOPLIMIT;
cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));
/* Set the outbound interface */
cm = CMSG_FIRSTHDR(&ctx->sndhdr);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(pi));
/* Hop limit */
cm = CMSG_NXTHDR(&ctx->sndhdr, cm);
+ if (cm == NULL) /* unlikely */
+ return;
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_HOPLIMIT;
cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));