summaryrefslogtreecommitdiff
path: root/usr.sbin/snmpd/snmpd.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/snmpd/snmpd.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/snmpd/snmpd.c')
-rw-r--r--usr.sbin/snmpd/snmpd.c14
1 files changed, 10 insertions, 4 deletions
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 <reyk@openbsd.org>
@@ -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] &&