/* NOTREACHED */
}
#endif
-
-#ifndef xstrdup
-char *
-xstrdup(const char *str)
-{
- char *value;
-
- if (str == NULL)
- return NULL;
-
- if ((value = strdup(str)) != NULL)
- return value;
-
- syslog(LOG_ERR, "memory exhausted (xstrdup)");
- exit(EXIT_FAILURE);
- /* NOTREACHED */
-}
-#endif
time_t uptime(void);
int writepid(int, pid_t);
void *xmalloc(size_t);
-char *xstrdup(const char *);
#endif
const struct dhcp_opt *opt;
int match, n;
- o = p = xstrdup(opts);
+ o = p = strdup(opts);
+ if (opts == NULL)
+ return -1;
while ((token = strsep(&p, ", "))) {
if (*token == '\0')
continue;
a = get_option_string(dhcp, DHO_MESSAGE);
else if (dhcp->yiaddr != 0) {
addr.s_addr = dhcp->yiaddr;
- a = xstrdup(inet_ntoa(addr));
+ a = strdup(inet_ntoa(addr));
+ if (a == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return;
+ }
} else
a = NULL;
size_t i = 0, l, lv;
char *match = NULL, *p, *n;
- match = xstrdup(value);
+ match = strdup(value);
+ if (match == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return NULL;
+ }
p = strchr(match, '=');
if (p)
*p++ = '\0';
while (lst && lst[i]) {
if (match && strncmp(lst[i], match, l) == 0) {
if (uniq) {
+ n = strdup(value);
+ if (n == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return NULL;
+ }
free(lst[i]);
- lst[i] = xstrdup(value);
+ lst[i] = n;
} else {
/* Append a space and the value to it */
l = strlen(lst[i]);
i++;
}
+ n = strdup(value);
+ if (n == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return NULL;
+ }
newlist = realloc(lst, sizeof(char *) * (i + 2));
if (newlist == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
return NULL;
}
- newlist[i] = xstrdup(value);
+ newlist[i] = n;
newlist[i + 1] = NULL;
ifo->environ = newlist;
free(match);
splitv(int *argc, char **argv, const char *arg)
{
char **n, **v = argv;
- char *o = xstrdup(arg), *p, *t, *nt;
+ char *o = strdup(arg), *p, *t, *nt;
+ if (o == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return v;
+ }
p = o;
while ((t = strsep(&p, ", "))) {
nt = strdup(t);
if (strncmp(ifo->config[s], arg,
p - arg) == 0)
{
+ p = strdup(arg);
+ if (p == NULL) {
+ syslog(LOG_ERR,
+ "%s: %m", __func__);
+ return -1;
+ }
free(ifo->config[s]);
- ifo->config[s] = xstrdup(arg);
+ ifo->config[s] = p;
return 1;
}
s++;
}
}
- nconf = realloc(ifo->config, sizeof(char *) * (s + 2));
+ p = strdup(arg);
if (p == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
+ nconf = realloc(ifo->config, sizeof(char *) * (s + 2));
+ if (nconf == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return -1;
+ }
ifo->config = nconf;
- ifo->config[s] = xstrdup(arg);
+ ifo->config[s] = p;
ifo->config[s + 1] = NULL;
}
break;
break;
case O_FALLBACK:
free(ifo->fallback);
- ifo->fallback = xstrdup(arg);
+ ifo->fallback = strdup(arg);
+ if (ifo->fallback == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return -1;
+ }
break;
#endif
case O_IPV6RS:
strcpy(opt + l + 1, ap->saddr);
}
} else
- opt = xstrdup(ap->saddr);
+ opt = strdup(ap->saddr);
lifetime = ap->prefix_vltime;
break;
}
rap->mtu = mtuv;
snprintf(buf, sizeof(buf), "%d", mtuv);
- opt = xstrdup(buf);
+ opt = strdup(buf);
break;
case ND_OPT_RDNSS:
syslog(LOG_ERR, "%s: invalid DNSSL option",
ifp->name);
} else {
- tmp = xmalloc(l);
- decode_rfc3397(tmp, l, n, op);
- n = print_string(NULL, 0,
- l - 1, (const uint8_t *)tmp);
- opt = xmalloc(n);
- print_string(opt, n,
- l - 1, (const uint8_t *)tmp);
- free(tmp);
+ tmp = malloc(l);
+ if (tmp) {
+ decode_rfc3397(tmp, l, n, op);
+ n = print_string(NULL, 0,
+ l - 1, (const uint8_t *)tmp);
+ opt = malloc(n);
+ if (opt)
+ print_string(opt, n,
+ l - 1,
+ (const uint8_t *)tmp);
+ free(tmp);
+ }
}
break;
}
- if (opt == NULL)
+ if (opt == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
continue;
+ }
TAILQ_FOREACH(rao, &rap->options, next) {
if (rao->type == ndo->nd_opt_type &&
strcmp(rao->option, opt) == 0)
check_ipv6(const char *ifname)
{
int r, ex, i;
- char path[256];
+ char path[256], *p, **nrest;
if (ifname == NULL) {
ifname = "all";
if (strcmp(restore[i], ifname) == 0)
break;
if (i == nrestore) {
- restore = realloc(restore,
+ p = strdup(ifname);
+ if (p == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ goto forward;
+ }
+ nrest = realloc(restore,
(nrestore + 1) * sizeof(char *));
- if (restore == NULL) {
- syslog(LOG_ERR, "realloc: %m");
- exit(EXIT_FAILURE);
+ if (nrest == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ goto forward;
}
- restore[nrestore++] = xstrdup(ifname);
+ restore = nrest;
+ restore[nrestore++] = p;
+
}
if (ex)
atexit(restore_kernel_ra);
}
+forward:
if (r != 2) {
snprintf(path, sizeof(path), "%s/%s/forwarding",
prefix, ifname);
env = nenv;
e = 0;
while (ifo->environ[e]) {
- env[elen + e] = xstrdup(ifo->environ[e]);
+ env[elen + e] = strdup(ifo->environ[e]);
+ if (env[elen + e] == NULL)
+ goto eexit;
e++;
}
elen += e;
e = strlen("PATH") + strlen(path) + 2;
env[elen] = xmalloc(e);
snprintf(env[elen], e, "PATH=%s", path);
- } else
- env[elen] = xstrdup(DEFAULT_PATH);
+ } else {
+ env[elen] = strdup(DEFAULT_PATH);
+ if (env[elen] == NULL) {
+ elen = -1;
+ goto out;
+ }
+ }
env[++elen] = '\0';
pid = exec_script(argv, env);