is non-portable. Also add missing asprintf() return value checks.
OK deraadt@ guenther@ doug@
-/* $OpenBSD: getgrouplist.c,v 1.24 2014/09/15 06:15:48 guenther Exp $ */
+/* $OpenBSD: getgrouplist.c,v 1.25 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2008 Ingo Schwarze <schwarze@usta.de>
* Copyright (c) 1991, 1993
if (getpwnam_r(uname, &pwstore, buf, sizeof buf, NULL) ||
(!__ypdomain && yp_get_default_domain(&__ypdomain)))
goto out;
- asprintf(&key, "unix.%u@%s", pwstore.pw_uid, __ypdomain);
- if (key == NULL)
+ i = asprintf(&key, "unix.%u@%s", pwstore.pw_uid, __ypdomain);
+ if (i == -1)
goto out;
/* First scan the static netid file. */
-/* $OpenBSD: getpwent.c,v 1.53 2015/01/16 16:48:51 deraadt Exp $ */
+/* $OpenBSD: getpwent.c,v 1.54 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2008 Theo de Raadt
* Copyright (c) 1988, 1993
__ypproto_set(pw, yppbuf, *flagsp, &yp_pw_flags);
if (!map) {
if (lookup == LOOKUP_BYNAME) {
+ if ((name = strdup(name)) == NULL) {
+ pw = NULL;
+ goto done;
+ }
map = PASSWD_BYNAME;
- name = strdup(name);
} else {
+ if (asprintf(&name, "%u", uid) == -1) {
+ pw = NULL;
+ goto done;
+ }
map = PASSWD_BYUID;
- asprintf(&name, "%u", uid);
}
}
-/* $OpenBSD: pidfile.c,v 1.10 2014/06/30 00:26:22 deraadt Exp $ */
+/* $OpenBSD: pidfile.c,v 1.11 2015/06/03 02:24:36 millert Exp $ */
/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
/*-
}
/* _PATH_VARRUN includes trailing / */
- (void) asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename);
- if (pidfile_path == NULL)
+ if (asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename) == -1)
return (-1);
if ((f = fopen(pidfile_path, "w")) == NULL) {
-/* $OpenBSD: prebind.c,v 1.28 2015/01/16 16:18:07 deraadt Exp $ */
+/* $OpenBSD: prebind.c,v 1.29 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
* NFS will return unknown, since load_file
* does stat the file, this just
*/
- asprintf(&buf, "%s/%s", name, dp->d_name);
+ if (asprintf(&buf, "%s/%s", name, dp->d_name) == -1) {
+ warn("asprintf");
+ goto done;
+ }
lstat(buf, &sb);
if (sb.st_mode == S_IFREG)
load_exe(buf);
free(buf);
break;
case DT_REG:
- asprintf(&buf, "%s/%s", name, dp->d_name);
+ if (asprintf(&buf, "%s/%s", name, dp->d_name) == -1) {
+ warn("asprintf");
+ goto done;
+ }
load_exe(buf);
free(buf);
break;
;
}
}
+done:
closedir(dirp);
}
-/* $OpenBSD: prebind_delete.c,v 1.12 2013/05/04 09:23:33 jsg Exp $ */
+/* $OpenBSD: prebind_delete.c,v 1.13 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
* NFS will return unknown, since load_file
* does stat the file, this just
*/
- asprintf(&buf, "%s/%s", dir, dp->d_name);
+ if (asprintf(&buf, "%s/%s", dir, dp->d_name) == -1) {
+ if (verbose)
+ warn("asprintf");
+ goto done;
+ }
lstat(buf, &sb);
if (sb.st_mode == S_IFREG)
ret = strip_prebind(buf);
free(buf);
break;
case DT_REG:
- asprintf(&buf, "%s/%s", dir, dp->d_name);
+ if (asprintf(&buf, "%s/%s", dir, dp->d_name) == -1) {
+ if (verbose)
+ warn("asprintf");
+ goto done;
+ }
ret = strip_prebind(buf);
free(buf);
break;
;
}
}
+done:
closedir(dirp);
return ret;
}
-/* $OpenBSD: spamd-setup.c,v 1.45 2015/01/20 16:54:06 millert Exp $ */
+/* $OpenBSD: spamd-setup.c,v 1.46 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2003 Bob Beck. All rights reserved.
return (open(file, O_RDONLY));
if ((strcmp(method, "http") == 0) ||
strcmp(method, "ftp") == 0) {
- asprintf(&url, "%s://%s", method, file);
- if (url == NULL)
+ if (asprintf(&url, "%s://%s", method, file) == -1)
return (-1);
i = fileget(url);
free(url);
len = strlen(file);
argv = calloc(len, sizeof(char *));
if (argv == NULL)
- err(1, NULL);
+ return (-1);
for (ap = argv; ap < &argv[len - 1] &&
(*ap = strsep(&file, " \t")) != NULL;) {
if (**ap != '\0')
-/* $OpenBSD: disklabel.c,v 1.201 2015/04/29 16:56:31 henning Exp $ */
+/* $OpenBSD: disklabel.c,v 1.202 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 1987, 1993
err(4, "ioctl DIOCGDINFO");
}
- asprintf(&partname, "/dev/%s%c", dkname, 'a');
- asprintf(&partduid,
+ i = asprintf(&partname, "/dev/%s%c", dkname, 'a');
+ if (i == -1)
+ err(4, NULL);
+ i = asprintf(&partduid,
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.a",
lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3],
lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7]);
+ if (i == -1)
+ err(4, NULL);
setfsent();
for (i = 0; i < MAXPARTITIONS; i++) {
partname[strlen(dkname) + 5] = 'a' + i;
-/* $OpenBSD: iked.c,v 1.23 2015/01/16 06:39:58 deraadt Exp $ */
+/* $OpenBSD: iked.c,v 1.24 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
/* FALLTHROUGH */
case SIGCHLD:
do {
+ int len;
+
pid = waitpid(-1, &status, WNOHANG);
if (pid <= 0)
continue;
fail = 0;
if (WIFSIGNALED(status)) {
fail = 1;
- asprintf(&cause, "terminated; signal %d",
+ len = asprintf(&cause, "terminated; signal %d",
WTERMSIG(status));
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
fail = 1;
- asprintf(&cause, "exited abnormally");
+ len = asprintf(&cause,
+ "exited abnormally");
} else
- asprintf(&cause, "exited okay");
+ len = asprintf(&cause, "exited okay");
} else
fatalx("unexpected cause of SIGCHLD");
+ if (len == -1)
+ fatal("asprintf");
+
die = 1;
for (id = 0; id < PROC_MAX; id++)
-/* $OpenBSD: parse.y,v 1.46 2015/02/08 04:50:32 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.47 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
if (prefixlen != 128) {
ipa->netaddress = 1;
- asprintf(&ipa->name, "%s/%d", hbuf, prefixlen);
- } else
- ipa->name = strdup(hbuf);
- if (ipa->name == NULL)
- err(1, "host_v6: strdup");
+ if (asprintf(&ipa->name, "%s/%d", hbuf, prefixlen) == -1)
+ err(1, "host_v6: asprintf");
+ } else {
+ if ((ipa->name = strdup(hbuf)) == NULL)
+ err(1, "host_v6: strdup");
+ }
freeaddrinfo(res);
-/* $OpenBSD: parse.y,v 1.161 2014/11/20 05:51:20 jsg Exp $ */
+/* $OpenBSD: parse.y,v 1.162 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
if (prefixlen != 128) {
ipa->netaddress = 1;
- asprintf(&ipa->name, "%s/%d", hbuf, prefixlen);
- } else
- ipa->name = strdup(hbuf);
- if (ipa->name == NULL)
- err(1, "host_v6: strdup");
+ if (asprintf(&ipa->name, "%s/%d", hbuf, prefixlen) == -1)
+ err(1, "host_v6: asprintf");
+ } else {
+ if ((ipa->name = strdup(hbuf)) == NULL)
+ err(1, "host_v6: strdup");
+ }
freeaddrinfo(res);
-/* $OpenBSD: field.c,v 1.19 2005/11/15 21:49:04 cloder Exp $ */
+/* $OpenBSD: field.c,v 1.20 2015/06/03 02:24:36 millert Exp $ */
/* $EOM: field.c,v 1.11 2000/02/20 19:58:37 niklas Exp $ */
/*
static char *
field_debug_num(u_int8_t *buf, size_t len, struct constant_map **maps)
{
- char *retval;
+ char *retval = NULL;
u_int32_t val;
if (extract_val(buf, len, &val))
return 0;
/* 3 decimal digits are enough to represent each byte. */
- asprintf(&retval, "%u", val);
+ (void)asprintf(&retval, "%u", val);
return retval;
}
-/* $OpenBSD: pfctl_parser.c,v 1.304 2015/02/14 23:32:41 sthen Exp $ */
+/* $OpenBSD: pfctl_parser.c,v 1.305 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
} else
snprintf(statline, sizeof(statline), "Status: %s", running);
printf("%-44s", statline);
- asprintf(&debug, "Debug: %s", loglevel_to_string(s->debug));
- printf("%15s\n\n", debug);
- free(debug);
+ if (asprintf(&debug, "Debug: %s", loglevel_to_string(s->debug)) != -1) {
+ printf("%15s\n\n", debug);
+ free(debug);
+ }
if (opts & PF_OPT_VERBOSE) {
printf("Hostid: 0x%08x\n", ntohl(s->hostid));
-/* $OpenBSD: httpd.c,v 1.36 2015/05/28 17:08:09 florian Exp $ */
+/* $OpenBSD: httpd.c,v 1.37 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
/* FALLTHROUGH */
case SIGCHLD:
do {
+ int len;
+
pid = waitpid(WAIT_ANY, &status, WNOHANG);
if (pid <= 0)
continue;
fail = 0;
if (WIFSIGNALED(status)) {
fail = 1;
- asprintf(&cause, "terminated; signal %d",
+ len = asprintf(&cause, "terminated; signal %d",
WTERMSIG(status));
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
fail = 1;
- asprintf(&cause, "exited abnormally");
+ len = asprintf(&cause,
+ "exited abnormally");
} else
- asprintf(&cause, "exited okay");
+ len = asprintf(&cause, "exited okay");
} else
fatalx("unexpected cause of SIGCHLD");
+ if (len == -1)
+ fatal("asprintf");
+
die = 1;
for (id = 0; id < PROC_MAX; id++)
-/* $OpenBSD: btree.c,v 1.32 2015/01/16 16:04:38 deraadt Exp $ */
+/* $OpenBSD: btree.c,v 1.33 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
if ((txn = btree_txn_begin(bt, 0)) == NULL)
return BT_FAIL;
- asprintf(&compact_path, "%s.compact.XXXXXX", bt->path);
+ if (asprintf(&compact_path, "%s.compact.XXXXXX", bt->path) == -1) {
+ btree_txn_abort(txn);
+ return BT_FAIL;
+ }
fd = mkstemp(compact_path);
if (fd == -1) {
free(compact_path);
-/* $OpenBSD: index.c,v 1.8 2010/11/26 14:44:01 martinh Exp $ */
+/* $OpenBSD: index.c,v 1.9 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2009 Martin Hedenfalk <martin@bzero.se>
bzero(&key, sizeof(key));
key.size = asprintf(&t, "%s=%s,%.*s", attr, s, dnsz,
(char *)dn->data);
+ if (key.size == (size_t)-1)
+ return -1;
key.data = t;
normalize_dn(key.data);
rc = btree_txn_put(NULL, ns->indx_txn, &key, &val,
++parent_dn;
}
- asprintf(&t, "@%.*s,%.*s", pdnsz, parent_dn, rdnsz, (char *)dn->data);
+ if (asprintf(&t, "@%.*s,%.*s", pdnsz, parent_dn, rdnsz,
+ (char *)dn->data) == -1)
+ return -1;
normalize_dn(t);
key->data = t;
-/* $OpenBSD: ldape.c,v 1.19 2015/01/16 16:04:38 deraadt Exp $ */
+/* $OpenBSD: ldape.c,v 1.20 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
ber_set_header(ref_root, BER_CLASS_CONTEXT, LDAP_REQ_SEARCH);
SLIST_FOREACH(ref, refs, next) {
if (search != NULL)
- asprintf(&url, "%s/%s??%s", ref->url, basedn,
+ rc = asprintf(&url, "%s/%s??%s", ref->url, basedn,
scope_str);
else
- asprintf(&url, "%s/%s", ref->url, basedn);
- if (url == NULL) {
+ rc = asprintf(&url, "%s/%s", ref->url, basedn);
+ if (rc == -1) {
log_warn("asprintf");
goto fail;
}
-/* $OpenBSD: search.c,v 1.14 2010/11/10 08:00:54 martinh Exp $ */
+/* $OpenBSD: search.c,v 1.15 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
{
struct index *indx;
va_list ap;
+ int rc;
if ((indx = calloc(1, sizeof(*indx))) == NULL)
return -1;
va_start(ap, fmt);
- vasprintf(&indx->prefix, fmt, ap);
+ rc = vasprintf(&indx->prefix, fmt, ap);
va_end(ap);
+ if (rc == -1) {
+ free(indx);
+ return -1;
+ }
normalize_dn(indx->prefix);
-/* $OpenBSD: relayd.c,v 1.141 2015/05/30 09:47:25 claudio Exp $ */
+/* $OpenBSD: relayd.c,v 1.142 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2007 - 2014 Reyk Floeter <reyk@openbsd.org>
/* FALLTHROUGH */
case SIGCHLD:
do {
+ int len;
+
pid = waitpid(WAIT_ANY, &status, WNOHANG);
if (pid <= 0)
continue;
fail = 0;
if (WIFSIGNALED(status)) {
fail = 1;
- asprintf(&cause, "terminated; signal %d",
+ len = asprintf(&cause, "terminated; signal %d",
WTERMSIG(status));
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
fail = 1;
- asprintf(&cause, "exited abnormally");
+ len = asprintf(&cause,
+ "exited abnormally");
} else
- asprintf(&cause, "exited okay");
+ len = asprintf(&cause, "exited okay");
} else
fatalx("unexpected cause of SIGCHLD");
+ if (len == -1)
+ fatal("asprintf");
+
die = 1;
for (id = 0; id < PROC_MAX; id++)
-/* $OpenBSD: dump.c,v 1.14 2013/11/12 22:27:13 deraadt Exp $ */
+/* $OpenBSD: dump.c,v 1.15 2015/06/03 02:24:36 millert Exp $ */
/* $KAME: dump.c,v 1.27 2002/05/29 14:23:55 itojun Exp $ */
/*
char *
lifetime(int lt)
{
- char *str;
+ char *str = NULL;
if (lt == ND6_INFINITE_LIFETIME)
- asprintf(&str, "infinity");
+ (void)asprintf(&str, "infinity");
else
- asprintf(&str, "%ld", (long)lt);
+ (void)asprintf(&str, "%ld", (long)lt);
return str;
}
-/* $OpenBSD: smtpd.c,v 1.238 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: smtpd.c,v 1.239 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
/* FALLTHROUGH */
case SIGCHLD:
do {
+ int len;
+
pid = waitpid(-1, &status, WNOHANG);
if (pid <= 0)
continue;
fail = 0;
if (WIFSIGNALED(status)) {
fail = 1;
- asprintf(&cause, "terminated; signal %d",
+ len = asprintf(&cause, "terminated; signal %d",
WTERMSIG(status));
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
fail = 1;
- asprintf(&cause, "exited abnormally");
+ len = asprintf(&cause,
+ "exited abnormally");
} else
- asprintf(&cause, "exited okay");
+ len = asprintf(&cause, "exited okay");
} else
fatalx("smtpd: unexpected cause of SIGCHLD");
+ if (len == -1)
+ fatal("asprintf");
+
if (pid == purge_pid)
purge_pid = -1;
case CHILD_MDA:
if (WIFSIGNALED(status) &&
WTERMSIG(status) == SIGALRM) {
- free(cause);
- asprintf(&cause, "terminated; timeout");
+ char *tmp;
+ if (asprintf(&tmp,
+ "terminated; timeout") != -1) {
+ free(cause);
+ cause = tmp;
+ }
}
else if (child->cause &&
WIFSIGNALED(status) &&
-/* $OpenBSD: snmpd.c,v 1.28 2015/05/28 17:08:09 florian Exp $ */
+/* $OpenBSD: snmpd.c,v 1.29 2015/06/03 02:24:36 millert Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
/* FALLTHROUGH */
case SIGCHLD:
do {
+ int len;
+
pid = waitpid(WAIT_ANY, &status, WNOHANG);
if (pid <= 0)
continue;
fail = 0;
if (WIFSIGNALED(status)) {
fail = 1;
- asprintf(&cause, "terminated; signal %d",
+ len = asprintf(&cause, "terminated; signal %d",
WTERMSIG(status));
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
fail = 1;
- asprintf(&cause, "exited abnormally");
+ len = asprintf(&cause,
+ "exited abnormally");
} else
- asprintf(&cause, "exited okay");
+ len = asprintf(&cause, "exited okay");
} else
fatalx("unexpected cause of SIGCHLD");
+
+ if (len == -1)
+ fatal("asprintf");
for (id = 0; id < PROC_MAX; id++) {
if (pid == ps->ps_pid[id] &&