diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2015-04-11 14:52:50 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2015-04-11 14:52:50 +0000 |
commit | 369a7e82c2eec436d483db601fda14d6b9eceb18 (patch) | |
tree | 08698961ee309d14e6e961b1b03f4fbc1725f589 /usr.sbin | |
parent | 0cda4e41394c4a41043ab63138a4fcbf09cb2fdf (diff) |
Always check the return value of proc_composev_imsg() and handle failures
appropriately. Otherwise imsg construction can silently fail, resulting in
non-obvious problems.
Found the hard way by Theodore Wynnychenko.
ok doug@ florian@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/httpd/config.c | 20 | ||||
-rw-r--r-- | usr.sbin/httpd/logger.c | 14 | ||||
-rw-r--r-- | usr.sbin/httpd/server.c | 8 |
3 files changed, 32 insertions, 10 deletions
diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c index 2dc915935b4..7635c33993e 100644 --- a/usr.sbin/httpd/config.c +++ b/usr.sbin/httpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.36 2015/02/23 11:48:41 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.37 2015/04/11 14:52:49 jsing Exp $ */ /* * Copyright (c) 2011 - 2015 Reyk Floeter <reyk@openbsd.org> @@ -212,12 +212,22 @@ config_setserver(struct httpd *env, struct server *srv) fd = -1; else if ((fd = dup(srv->srv_s)) == -1) return (-1); - proc_composev_imsg(ps, id, n, - IMSG_CFG_SERVER, fd, iov, c); + if (proc_composev_imsg(ps, id, n, + IMSG_CFG_SERVER, fd, iov, c) != 0) { + log_warn("%s: failed to compose " + "IMSG_CFG_SERVER imsg for `%s'", + __func__, srv->srv_conf.name); + return (-1); + } } } else { - proc_composev_imsg(ps, id, -1, IMSG_CFG_SERVER, -1, - iov, c); + if (proc_composev_imsg(ps, id, -1, IMSG_CFG_SERVER, -1, + iov, c) != 0) { + log_warn("%s: failed to compose " + "IMSG_CFG_SERVER imsg for `%s'", + __func__, srv->srv_conf.name); + return (-1); + } } } diff --git a/usr.sbin/httpd/logger.c b/usr.sbin/httpd/logger.c index b4e440476ea..d03d954d894 100644 --- a/usr.sbin/httpd/logger.c +++ b/usr.sbin/httpd/logger.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logger.c,v 1.11 2015/02/08 00:00:59 reyk Exp $ */ +/* $OpenBSD: logger.c,v 1.12 2015/04/11 14:52:49 jsing Exp $ */ /* * Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org> @@ -118,12 +118,20 @@ logger_open_file(const char *name) iov[1].iov_base = log->log_name; iov[1].iov_len = strlen(log->log_name) + 1; - proc_composev_imsg(env->sc_ps, PROC_PARENT, -1, IMSG_LOG_OPEN, -1, - iov, 2); + if (proc_composev_imsg(env->sc_ps, PROC_PARENT, -1, IMSG_LOG_OPEN, -1, + iov, 2) != 0) { + log_warn("%s: failed to compose IMSG_LOG_OPEN imsg", __func__); + goto err; + } TAILQ_INSERT_TAIL(&log_files, log, log_entry); return (log); + +err: + free(log); + + return (NULL); } int diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index 281d3eea36a..fe47cf431e9 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.61 2015/03/15 22:08:45 florian Exp $ */ +/* $OpenBSD: server.c,v 1.62 2015/04/11 14:52:49 jsing Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org> @@ -1010,7 +1010,11 @@ server_sendlog(struct server_config *srv_conf, int cmd, const char *emsg, ...) iov[1].iov_base = msg; iov[1].iov_len = strlen(msg) + 1; - proc_composev_imsg(env->sc_ps, PROC_LOGGER, -1, cmd, -1, iov, 2); + if (proc_composev_imsg(env->sc_ps, PROC_LOGGER, -1, cmd, -1, iov, + 2) != 0) { + log_warn("%s: failed to compose imsg", __func__); + return; + } } void |