/* NOTREACHED */
}
#endif
-
-void *
-xzalloc(size_t s)
-{
- void *value = xmalloc(s);
-
- memset(value, 0, s);
- return value;
-}
int writepid(int, pid_t);
void *xrealloc(void *, size_t);
void *xmalloc(size_t);
-void *xzalloc(size_t);
char *xstrdup(const char *);
#endif
}
if (rt) {
- rt->next = xzalloc(sizeof(*rt));
+ rt->next = calloc(1, sizeof(*rt));
rt = rt->next;
} else {
- routes = rt = xzalloc(sizeof(*routes));
+ routes = rt = calloc(1, sizeof(*routes));
+ }
+ if (rt == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ ipv4_freeroutes(routes);
+ return NULL;
}
rt->next = NULL;
e = p + len;
while (p < e) {
if (route) {
- route->next = xmalloc(sizeof(*route));
+ route->next = calloc(1, sizeof(*route));
route = route->next;
} else
- routes = route = xmalloc(sizeof(*routes));
+ routes = route = calloc(1, sizeof(*routes));
+ if (route == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ break;
+ }
route->next = NULL;
memcpy(&route->dest.s_addr, p, 4);
p += 4;
e = p + len;
while (p < e) {
if (route) {
- route->next = xzalloc(sizeof(*route));
+ route->next = calloc(1, sizeof(*route));
route = route->next;
} else
- routes = route = xzalloc(sizeof(*route));
+ routes = route = calloc(1, sizeof(*route));
+ if (route == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ break;
+ }
memcpy(&route->gate.s_addr, p, 4);
p += 4;
}
const struct dhcp_lease *lease = &state->lease;
time_t up = uptime() - state->start_uptime;
- dhcp = xzalloc(sizeof (*dhcp));
+ dhcp = calloc(1, sizeof (*dhcp));
+ if (dhcp == NULL)
+ return -1;
m = (uint8_t *)dhcp;
p = dhcp->options;
struct ip *ip;
struct udphdr *udp;
- udpp = xzalloc(sizeof(*udpp));
+ udpp = calloc(1, sizeof(*udpp));
+ if (udpp == NULL)
+ return -1;
ip = &udpp->ip;
udp = &udpp->udp;
}
} else {
len = dhcp_makeudppacket(&udp, (uint8_t *)dhcp, len, from, to);
+ if (len == -1)
+ return;
r = ipv4_sendrawpacket(iface, ETHERTYPE_IP, udp, len);
free(udp);
/* If we failed to send a raw packet this normally means
struct dhcp_message *dhcp;
uint8_t *p;
- dhcp = xzalloc(sizeof(*dhcp));
+ dhcp = calloc(1, sizeof(*dhcp));
+ if (dhcp == NULL)
+ return NULL;
dhcp->yiaddr = addr->s_addr;
p = dhcp->options;
if (mask && mask->s_addr != INADDR_ANY) {
iface->name, inet_ntoa(from));
continue;
}
- if (!dhcp)
- dhcp = xzalloc(sizeof(*dhcp));
+ if (dhcp == NULL) {
+ dhcp = calloc(1, sizeof(*dhcp));
+ if (dhcp == NULL) {
+ syslog(LOG_ERR, "%s: calloc: %m", __func__);
+ break;
+ }
+ }
memcpy(dhcp, pp, bytes);
if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
syslog(LOG_DEBUG, "%s: bogus cookie from %s",
struct interface *ifp;
struct dhcp_state *state;
- ifaces = ifp = xzalloc(sizeof(*ifp));
- ifp->if_data[IF_DATA_DHCP] = state = xzalloc(sizeof(*state));
- ifp->options = xzalloc(sizeof(*ifp->options));
+ ifaces = ifp = calloc(1, sizeof(*ifp));
+ if (ifp == NULL)
+ goto eexit;
+ ifp->if_data[IF_DATA_DHCP] = state = calloc(1, sizeof(*state));
+ if (state == NULL)
+ goto eexit;
+ ifp->options = calloc(1, sizeof(*ifp->options));
+ if (ifp->options == NULL)
+ goto eexit;
strlcpy(ifp->name, ifname, sizeof(ifp->name));
snprintf(state->leasefile, sizeof(state->leasefile),
LEASEFILE, ifp->name);
}
state->reason = "DUMP";
return script_runreason(ifp, state->reason);
+
+eexit:
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return -1;
}
void
configure_interface(ifp, argc, argv);
ifo = ifp->options;
- if (if_options->options & DHCPCD_LINK && linkfd == -1) {
+ if (ifo->options & DHCPCD_LINK && linkfd == -1) {
linkfd = open_link_socket();
if (linkfd == -1) {
syslog(LOG_ERR, "open_link_socket: %m");
struct nlma *nlm;
int retval = 0;
- nlm = xzalloc(sizeof(*nlm));
+ nlm = calloc(1, sizeof(*nlm));
+ if (nlm == NULL)
+ return -1;
nlm->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
nlm->hdr.nlmsg_flags = NLM_F_REQUEST;
if (action >= 0) {
int retval = 0;
struct dhcp_state *state;
- nlm = xzalloc(sizeof(*nlm));
+ nlm = calloc(1, sizeof(*nlm));
+ if (nlm == NULL)
+ return -1;
nlm->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
nlm->hdr.nlmsg_type = RTM_NEWROUTE;
if (action == 0)
struct ifa_cacheinfo cinfo;
int retval = 0;
- nlm = xzalloc(sizeof(*nlm));
+ nlm = calloc(1, sizeof(*nlm));
+ if (nlm == NULL)
+ return -1;
nlm->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
nlm->hdr.nlmsg_flags = NLM_F_REQUEST;
if (action >= 0) {
struct rtattr *metrics = (void *)metricsbuf;
int retval = 0;
- nlm = xzalloc(sizeof(*nlm));
+ nlm = calloc(1, sizeof(*nlm));
+ if (nlm == NULL)
+ return -1;
nlm->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
nlm->hdr.nlmsg_type = RTM_NEWROUTE;
nlm->hdr.nlmsg_flags = NLM_F_REQUEST;
while (*np == ' ')
np++;
if (ifo->routes == NULL) {
- rt = ifo->routes = xmalloc(sizeof(*rt));
+ rt = ifo->routes = calloc(1, sizeof(*rt));
+ if (rt == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ *fp = ' ';
+ return -1;
+ }
} else {
rt = ifo->routes;
while (rt->next)
*fp = ' ';
} else if (strncmp(arg, "routers=", strlen("routers=")) == 0) {
if (ifo->routes == NULL) {
- rt = ifo->routes = xzalloc(sizeof(*rt));
+ rt = ifo->routes = calloc(1, sizeof(*rt));
+ if (rt == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return -1;
+ }
} else {
rt = ifo->routes;
while (rt->next)
int skip = 0, have_profile = 0;
/* Seed our default options */
- ifo = xzalloc(sizeof(*ifo));
+ ifo = calloc(1, sizeof(*ifo));
+ if (ifo == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return NULL;
+ }
ifo->options |= DHCPCD_DAEMONISE | DHCPCD_LINK;
#ifdef INET
ifo->options |= DHCPCD_IPV4 | DHCPCD_IPV4LL;
struct dhcp_message *dhcp;
uint8_t *p;
- dhcp = xzalloc(sizeof(*dhcp));
+ dhcp = calloc(1, sizeof(*dhcp));
+ if (dhcp == NULL)
+ return NULL;
/* Put some LL options in */
dhcp->yiaddr = addr;
p = dhcp->options;
state->offer = ipv4ll_find_lease(addr);
else
state->offer = ipv4ll_make_lease(addr);
- state->lease.frominfo = 0;
- arp_probe(ifp);
+ if (state->offer == NULL)
+ syslog(LOG_ERR, "%s: %m", __func__);
+ else {
+ state->lease.frominfo = 0;
+ arp_probe(ifp);
+ }
}
void
{
struct rt6 *r;
- r = xzalloc(sizeof(*r));
+ r = calloc(1, sizeof(*r));
+ if (r == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return NULL;
+ }
r->ra = rap;
r->iface = ifp;
r->metric = ifp->metric;
return NULL;
r = make_route(ifp, rap);
+ if (r == NULL)
+ return r;
r->dest = addr->prefix;
ipv6_mask(&r->net, addr->prefix_len);
r->gate = in6addr_any;
struct rt6 *r;
r = make_route(rap->iface, rap);
+ if (r == NULL)
+ return NULL;
r->dest = in6addr_any;
r->net = in6addr_any;
r->gate = rap->from;
state = RS_STATE(ifp);
free(state->rs);
state->rslen = sizeof(*rs) + ROUNDUP8(ifp->hwlen + 2);
- state->rs = xzalloc(state->rslen);
+ state->rs = calloc(1, state->rslen);
if (state->rs == NULL)
return -1;
rs = (struct nd_router_solicit *)(void *)state->rs;
new_data = 0;
if (rap == NULL) {
- rap = xzalloc(sizeof(*rap));
+ rap = calloc(1, sizeof(*rap));
+ if (rap == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return;
+ }
rap->iface = ifp;
memcpy(rap->from.s6_addr, from.sin6_addr.s6_addr,
sizeof(rap->from.s6_addr));
p = ifa->ifa_name;
}
- ifp = xzalloc(sizeof(*ifp));
+ ifp = calloc(1, sizeof(*ifp));
+ if (ifp == NULL)
+ return NULL;
strlcpy(ifp->name, p, sizeof(ifp->name));
ifp->flags = ifa->ifa_flags;