From aa48e8d13779c959af7d1e175e87101276d885ff Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 3 Jun 2015 02:24:36 +0000 Subject: [PATCH] Do not assume that asprintf() clears the pointer on failure, which is non-portable. Also add missing asprintf() return value checks. OK deraadt@ guenther@ doug@ --- lib/libc/gen/getgrouplist.c | 6 +++--- lib/libc/gen/getpwent.c | 12 +++++++++--- lib/libutil/pidfile.c | 5 ++--- libexec/ld.so/ldconfig/prebind.c | 13 ++++++++++--- libexec/ld.so/ldconfig/prebind_delete.c | 15 ++++++++++++--- libexec/spamd-setup/spamd-setup.c | 7 +++---- sbin/disklabel/disklabel.c | 10 +++++++--- sbin/iked/iked.c | 14 ++++++++++---- sbin/iked/parse.y | 13 +++++++------ sbin/ipsecctl/parse.y | 13 +++++++------ sbin/isakmpd/field.c | 6 +++--- sbin/pfctl/pfctl_parser.c | 9 +++++---- usr.sbin/httpd/httpd.c | 14 ++++++++++---- usr.sbin/ldapd/btree.c | 7 +++++-- usr.sbin/ldapd/index.c | 8 ++++++-- usr.sbin/ldapd/ldape.c | 8 ++++---- usr.sbin/ldapd/search.c | 9 +++++++-- usr.sbin/relayd/relayd.c | 14 ++++++++++---- usr.sbin/rtadvd/dump.c | 8 ++++---- usr.sbin/smtpd/smtpd.c | 22 ++++++++++++++++------ usr.sbin/snmpd/snmpd.c | 14 ++++++++++---- 21 files changed, 150 insertions(+), 77 deletions(-) diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c index 651231124dd..79f6da75e8b 100644 --- a/lib/libc/gen/getgrouplist.c +++ b/lib/libc/gen/getgrouplist.c @@ -1,4 +1,4 @@ -/* $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 * Copyright (c) 1991, 1993 @@ -204,8 +204,8 @@ getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt) 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. */ diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 45f64fdf873..2d58e3f9bec 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $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 @@ -542,11 +542,17 @@ __yppwlookup(int lookup, char *name, uid_t uid, struct passwd *pw, __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); } } diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index 9bb68eb15b8..4c365d023ea 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -61,8 +61,7 @@ pidfile(const char *basename) } /* _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) { diff --git a/libexec/ld.so/ldconfig/prebind.c b/libexec/ld.so/ldconfig/prebind.c index cb7e4535d49..785929b7663 100644 --- a/libexec/ld.so/ldconfig/prebind.c +++ b/libexec/ld.so/ldconfig/prebind.c @@ -1,4 +1,4 @@ -/* $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 * @@ -268,14 +268,20 @@ load_dir(char *name) * 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; @@ -284,6 +290,7 @@ load_dir(char *name) ; } } +done: closedir(dirp); } diff --git a/libexec/ld.so/ldconfig/prebind_delete.c b/libexec/ld.so/ldconfig/prebind_delete.c index bc5eb77cad4..bbe5a9f3780 100644 --- a/libexec/ld.so/ldconfig/prebind_delete.c +++ b/libexec/ld.so/ldconfig/prebind_delete.c @@ -1,4 +1,4 @@ -/* $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 @@ -101,14 +101,22 @@ strip_dir(char *dir) * 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; @@ -118,6 +126,7 @@ strip_dir(char *dir) ; } } +done: closedir(dirp); return ret; } diff --git a/libexec/spamd-setup/spamd-setup.c b/libexec/spamd-setup/spamd-setup.c index f81430ab237..d12c84a03ee 100644 --- a/libexec/spamd-setup/spamd-setup.c +++ b/libexec/spamd-setup/spamd-setup.c @@ -1,4 +1,4 @@ -/* $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. @@ -298,8 +298,7 @@ open_file(char *method, char *file) 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); @@ -308,7 +307,7 @@ open_file(char *method, char *file) 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') diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 7b7e5a00965..bece1069620 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $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 @@ -471,11 +471,15 @@ readlabel(int f) 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; diff --git a/sbin/iked/iked.c b/sbin/iked/iked.c index 182b756dc02..9a9c7cdf1e4 100644 --- a/sbin/iked/iked.c +++ b/sbin/iked/iked.c @@ -1,4 +1,4 @@ -/* $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 @@ -289,6 +289,8 @@ parent_sig_handler(int sig, short event, void *arg) /* FALLTHROUGH */ case SIGCHLD: do { + int len; + pid = waitpid(-1, &status, WNOHANG); if (pid <= 0) continue; @@ -296,17 +298,21 @@ parent_sig_handler(int sig, short event, void *arg) 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++) diff --git a/sbin/iked/parse.y b/sbin/iked/parse.y index fbf5b29f5b9..33ea8c863cf 100644 --- a/sbin/iked/parse.y +++ b/sbin/iked/parse.y @@ -1,4 +1,4 @@ -/* $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 @@ -1770,11 +1770,12 @@ host_v6(const char *s, int prefixlen) 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); diff --git a/sbin/ipsecctl/parse.y b/sbin/ipsecctl/parse.y index 86d02492640..cab02d25c40 100644 --- a/sbin/ipsecctl/parse.y +++ b/sbin/ipsecctl/parse.y @@ -1,4 +1,4 @@ -/* $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 @@ -1613,11 +1613,12 @@ host_v6(const char *s, int prefixlen) 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); diff --git a/sbin/isakmpd/field.c b/sbin/isakmpd/field.c index 67cbffd12df..f7dccc27f8a 100644 --- a/sbin/isakmpd/field.c +++ b/sbin/isakmpd/field.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -95,13 +95,13 @@ extract_val(u_int8_t *buf, size_t len, u_int32_t *val) 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; } diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 65f0e030a3c..f9fb8a7c5bb 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -1,4 +1,4 @@ -/* $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 @@ -543,9 +543,10 @@ print_status(struct pf_status *s, int opts) } 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)); diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c index 5019fce6be3..5f6788c92e4 100644 --- a/usr.sbin/httpd/httpd.c +++ b/usr.sbin/httpd/httpd.c @@ -1,4 +1,4 @@ -/* $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 @@ -80,6 +80,8 @@ parent_sig_handler(int sig, short event, void *arg) /* FALLTHROUGH */ case SIGCHLD: do { + int len; + pid = waitpid(WAIT_ANY, &status, WNOHANG); if (pid <= 0) continue; @@ -87,17 +89,21 @@ parent_sig_handler(int sig, short event, void *arg) 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++) diff --git a/usr.sbin/ldapd/btree.c b/usr.sbin/ldapd/btree.c index cbba2ba5c54..eaf0d2fb7c7 100644 --- a/usr.sbin/ldapd/btree.c +++ b/usr.sbin/ldapd/btree.c @@ -1,4 +1,4 @@ -/* $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 @@ -3071,7 +3071,10 @@ btree_compact(struct btree *bt) 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); diff --git a/usr.sbin/ldapd/index.c b/usr.sbin/ldapd/index.c index 8d1b0f8d320..c8dbb7f6198 100644 --- a/usr.sbin/ldapd/index.c +++ b/usr.sbin/ldapd/index.c @@ -1,4 +1,4 @@ -/* $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 @@ -107,6 +107,8 @@ index_attribute(struct namespace *ns, char *attr, struct btval *dn, 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, @@ -141,7 +143,9 @@ index_rdn_key(struct namespace *ns, struct btval *dn, struct btval *key) ++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; diff --git a/usr.sbin/ldapd/ldape.c b/usr.sbin/ldapd/ldape.c index 58a698fcf14..48bc298db74 100644 --- a/usr.sbin/ldapd/ldape.c +++ b/usr.sbin/ldapd/ldape.c @@ -1,4 +1,4 @@ -/* $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 @@ -143,11 +143,11 @@ ldap_refer(struct request *req, const char *basedn, struct search *search, 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; } diff --git a/usr.sbin/ldapd/search.c b/usr.sbin/ldapd/search.c index 3afd62561c0..d2fa8bab8cf 100644 --- a/usr.sbin/ldapd/search.c +++ b/usr.sbin/ldapd/search.c @@ -1,4 +1,4 @@ -/* $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 @@ -619,13 +619,18 @@ add_index(struct plan *plan, const char *fmt, ...) { 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); diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c index b39956e914a..b4a5a7aa2ce 100644 --- a/usr.sbin/relayd/relayd.c +++ b/usr.sbin/relayd/relayd.c @@ -1,4 +1,4 @@ -/* $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 @@ -87,6 +87,8 @@ parent_sig_handler(int sig, short event, void *arg) /* FALLTHROUGH */ case SIGCHLD: do { + int len; + pid = waitpid(WAIT_ANY, &status, WNOHANG); if (pid <= 0) continue; @@ -94,17 +96,21 @@ parent_sig_handler(int sig, short event, void *arg) 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++) diff --git a/usr.sbin/rtadvd/dump.c b/usr.sbin/rtadvd/dump.c index a65befc9b9f..aa8856d89e3 100644 --- a/usr.sbin/rtadvd/dump.c +++ b/usr.sbin/rtadvd/dump.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -90,12 +90,12 @@ ether_str(sdl) 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; } diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index efb3a48b631..820c6750c28 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $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 @@ -333,6 +333,8 @@ parent_sig_handler(int sig, short event, void *p) /* FALLTHROUGH */ case SIGCHLD: do { + int len; + pid = waitpid(-1, &status, WNOHANG); if (pid <= 0) continue; @@ -340,17 +342,21 @@ parent_sig_handler(int sig, short event, void *p) 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; @@ -369,8 +375,12 @@ parent_sig_handler(int sig, short event, void *p) 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) && diff --git a/usr.sbin/snmpd/snmpd.c b/usr.sbin/snmpd/snmpd.c index b88154bbb00..f2df1ee7f68 100644 --- a/usr.sbin/snmpd/snmpd.c +++ b/usr.sbin/snmpd/snmpd.c @@ -1,4 +1,4 @@ -/* $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 @@ -72,6 +72,8 @@ snmpd_sig_handler(int sig, short event, void *arg) /* FALLTHROUGH */ case SIGCHLD: do { + int len; + pid = waitpid(WAIT_ANY, &status, WNOHANG); if (pid <= 0) continue; @@ -79,16 +81,20 @@ snmpd_sig_handler(int sig, short event, void *arg) 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] && -- 2.20.1