From: jsing Date: Sat, 11 Apr 2015 14:52:49 +0000 (+0000) Subject: Always check the return value of proc_composev_imsg() and handle failures X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=59ac4ec777e796070c97c94d0d6db31e5ed4b283;p=openbsd 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@ --- 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 @@ -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 @@ -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 @@ -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