Always check the return value of proc_composev_imsg() and handle failures
authorjsing <jsing@openbsd.org>
Sat, 11 Apr 2015 14:52:49 +0000 (14:52 +0000)
committerjsing <jsing@openbsd.org>
Sat, 11 Apr 2015 14:52:49 +0000 (14:52 +0000)
appropriately. Otherwise imsg construction can silently fail, resulting in
non-obvious problems.

Found the hard way by Theodore Wynnychenko.

ok doug@ florian@

usr.sbin/httpd/config.c
usr.sbin/httpd/logger.c
usr.sbin/httpd/server.c

index 2dc9159..7635c33 100644 (file)
@@ -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);
+                       }
                }
        }
 
index b4e4404..d03d954 100644 (file)
@@ -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
index 281d3ee..fe47cf4 100644 (file)
@@ -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