Commit Diff


commit - 5728bd4f29e4bd6eafe8898abea7758b4e84015b
commit + 78044f5e33d9650ea644a1c64770dd318e39e1f5
blob - f5d8143a24bb7dc251d1114a90fcdc7f5f43eb7c
blob + 9a4eb3b5163303aeae40221a06aeaaabb11c5c72
--- control.c
+++ control.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: control.c,v 1.20 2024/11/21 13:21:34 claudio Exp $	*/
+/*	$OpenBSD: control.c,v 1.21 2024/11/21 13:38:45 claudio Exp $	*/
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -159,12 +159,17 @@ control_accept(int listenfd, short event, void *arg)
 	}
 
 	if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) {
-		close(connfd);
 		log_warn("%s: calloc", __func__);
+		close(connfd);
 		return;
 	}
 
-	imsgbuf_init(&c->iev.ibuf, connfd);
+	if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) {
+		log_warn("%s: imsgbuf_init", __func__);
+		close(connfd);
+		free(c);
+		return;
+	}
 	c->iev.handler = control_dispatch_imsg;
 	c->iev.events = EV_READ;
 	c->iev.data = cs;	/* proc.c cheats (reuses the handler) */
blob - 972946f82a498cd750eafc1ebf53f368d0f96f91
blob + 66d528668df8490e31f639c477fd44392d80bc38
--- proc.c
+++ proc.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: proc.c,v 1.51 2024/11/21 13:21:34 claudio Exp $	*/
+/*	$OpenBSD: proc.c,v 1.52 2024/11/21 13:38:45 claudio Exp $	*/
 
 /*
  * Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -155,8 +155,10 @@ proc_connect(struct privsep *ps)
 
 		for (inst = 0; inst < ps->ps_instances[dst]; inst++) {
 			iev = &ps->ps_ievs[dst][inst];
-			imsgbuf_init(&iev->ibuf,
-			    ps->ps_pp->pp_pipes[dst][inst]);
+			if (imsgbuf_init(&iev->ibuf,
+			    ps->ps_pp->pp_pipes[dst][inst]) == -1)
+				fatal(NULL);
+			imsgbuf_allow_fdpass(&iev->ibuf);
 			event_set(&iev->ev, iev->ibuf.fd, iev->events,
 			    iev->handler, iev->data);
 			event_add(&iev->ev, NULL);
@@ -265,7 +267,9 @@ proc_accept(struct privsep *ps, int fd, enum privsep_p
 		pp->pp_pipes[dst][n] = fd;
 
 	iev = &ps->ps_ievs[dst][n];
-	imsgbuf_init(&iev->ibuf, fd);
+	if (imsgbuf_init(&iev->ibuf, fd) == -1)
+		fatal(NULL);
+	imsgbuf_allow_fdpass(&iev->ibuf);
 	event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data);
 	event_add(&iev->ev, NULL);
 }