summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/smtpd.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2015-06-03 02:24:37 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2015-06-03 02:24:37 +0000
commit53f83ea972c751a287eed99558f9349e7238bc9f (patch)
tree98e3342250c23ad4626e591e9c43381815c024c7 /usr.sbin/smtpd/smtpd.c
parentcf757a3268b6ecc9b77a4d2c3e3d4932433013a3 (diff)
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@
Diffstat (limited to 'usr.sbin/smtpd/smtpd.c')
-rw-r--r--usr.sbin/smtpd/smtpd.c22
1 files changed, 16 insertions, 6 deletions
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 <gilles@poolp.org>
@@ -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) &&