1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

Convert sbin and usr.bin to check for imsgbuf_init failure and add

imsgbuf_allow_fdpass where needed.

OK tb@
This commit is contained in:
claudio 2024-11-21 13:35:20 +00:00
parent af27b3cce1
commit 0e59d0d19c
21 changed files with 139 additions and 58 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.8 2024/11/21 13:21:33 claudio Exp $ */
/* $OpenBSD: control.c,v 1.9 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -156,7 +156,12 @@ control_accept(int listenfd, short event, void *bula)
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;
event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: dhcp6leased.c,v 1.18 2024/11/21 13:21:33 claudio Exp $ */
/* $OpenBSD: dhcp6leased.c,v 1.19 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017, 2021, 2024 Florian Obser <florian@openbsd.org>
@ -260,9 +260,13 @@ main(int argc, char *argv[])
if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
(iev_engine = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
if (imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_frontend->ibuf);
iev_frontend->handler = main_dispatch_frontend;
imsgbuf_init(&iev_engine->ibuf, pipe_main2engine[0]);
if (imsgbuf_init(&iev_engine->ibuf, pipe_main2engine[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_engine->ibuf);
iev_engine->handler = main_dispatch_engine;
/* Setup event handlers for pipes to engine & frontend. */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: engine.c,v 1.29 2024/11/21 13:21:33 claudio Exp $ */
/* $OpenBSD: engine.c,v 1.30 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017, 2021, 2024 Florian Obser <florian@openbsd.org>
@ -215,7 +215,9 @@ engine(int debug, int verbose)
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = engine_dispatch_main;
/* Setup event handlers. */
@ -423,7 +425,8 @@ engine_dispatch_main(int fd, short event, void *bula)
if (iev_frontend == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, fd);
if (imsgbuf_init(&iev_frontend->ibuf, fd) == -1)
fatal(NULL);
iev_frontend->handler = engine_dispatch_frontend;
iev_frontend->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: frontend.c,v 1.19 2024/11/21 13:21:33 claudio Exp $ */
/* $OpenBSD: frontend.c,v 1.20 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017, 2021, 2024 Florian Obser <florian@openbsd.org>
@ -180,7 +180,9 @@ frontend(int debug, int verbose)
/* Setup pipe and event handler to the parent process. */
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = frontend_dispatch_main;
iev_main->events = EV_READ;
event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
@ -282,7 +284,8 @@ frontend_dispatch_main(int fd, short event, void *bula)
if (iev_engine == NULL)
fatal(NULL);
imsgbuf_init(&iev_engine->ibuf, fd);
if (imsgbuf_init(&iev_engine->ibuf, fd) == -1)
fatal(NULL);
iev_engine->handler = frontend_dispatch_engine;
iev_engine->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.11 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: control.c,v 1.12 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -156,7 +156,12 @@ control_accept(int listenfd, short event, void *bula)
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;
event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: dhcpleased.c,v 1.38 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: dhcpleased.c,v 1.39 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -273,9 +273,13 @@ main(int argc, char *argv[])
if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
(iev_engine = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
if (imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_frontend->ibuf);
iev_frontend->handler = main_dispatch_frontend;
imsgbuf_init(&iev_engine->ibuf, pipe_main2engine[0]);
if (imsgbuf_init(&iev_engine->ibuf, pipe_main2engine[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_engine->ibuf);
iev_engine->handler = main_dispatch_engine;
/* Setup event handlers for pipes to engine & frontend. */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: engine.c,v 1.54 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: engine.c,v 1.55 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -226,7 +226,9 @@ engine(int debug, int verbose)
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = engine_dispatch_main;
/* Setup event handlers. */
@ -446,7 +448,8 @@ engine_dispatch_main(int fd, short event, void *bula)
if (iev_frontend == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, fd);
if (imsgbuf_init(&iev_frontend->ibuf, fd) == -1)
fatal(NULL);
iev_frontend->handler = engine_dispatch_frontend;
iev_frontend->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: frontend.c,v 1.44 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: frontend.c,v 1.45 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -177,7 +177,9 @@ frontend(int debug, int verbose)
/* Setup pipe and event handler to the parent process. */
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = frontend_dispatch_main;
iev_main->events = EV_READ;
event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
@ -283,7 +285,8 @@ frontend_dispatch_main(int fd, short event, void *bula)
if (iev_engine == NULL)
fatal(NULL);
imsgbuf_init(&iev_engine->ibuf, fd);
if (imsgbuf_init(&iev_engine->ibuf, fd) == -1)
fatal(NULL);
iev_engine->handler = frontend_dispatch_engine;
iev_engine->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.44 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: control.c,v 1.45 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@ -191,7 +191,12 @@ control_accept(int listenfd, short event, void *arg)
return;
}
imsgbuf_init(&c->iev.ibuf, connfd);
if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) {
log_warn("%s", __func__);
close(connfd);
free(c);
return;
}
c->iev.handler = control_dispatch_imsg;
c->iev.events = EV_READ;
c->iev.data = cs;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: proc.c,v 1.50 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: proc.c,v 1.51 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
@ -162,8 +162,10 @@ proc_connect(struct privsep *ps, void (*connected)(struct privsep *))
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("%s: imsgbuf_init", __func__);
imsgbuf_allow_fdpass(&iev->ibuf);
event_set(&iev->ev, iev->ibuf.fd, iev->events,
iev->handler, iev->data);
event_add(&iev->ev, NULL);
@ -293,7 +295,9 @@ proc_accept(struct privsep *ps, int fd, enum privsep_procid dst,
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("%s: imsgbuf_init", __func__);
imsgbuf_allow_fdpass(&iev->ibuf);
event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data);
event_add(&iev->ev, NULL);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mountd.c,v 1.95 2024/11/21 13:24:07 claudio Exp $ */
/* $OpenBSD: mountd.c,v 1.96 2024/11/21 13:35:20 claudio Exp $ */
/* $NetBSD: mountd.c,v 1.31 1996/02/18 11:57:53 fvdl Exp $ */
/*
@ -321,7 +321,10 @@ main(int argc, char *argv[])
}
signal(SIGTERM, (void (*)(int)) send_umntall);
imsgbuf_init(&ibuf, socks[0]);
if (imsgbuf_init(&ibuf, socks[0]) == -1) {
syslog(LOG_ERR, "imsgbuf_init: %m");
exit(1);
}
setproctitle("parent");
if (debug)
@ -370,7 +373,10 @@ privchild(int sock)
char *path;
int error, size;
imsgbuf_init(&ibuf, sock);
if (imsgbuf_init(&ibuf, sock) == -1) {
syslog(LOG_ERR, "imsgbuf_init: %m");
_exit(1);
}
setproctitle("[priv]");
fp = NULL;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.16 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: control.c,v 1.17 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -157,7 +157,12 @@ control_accept(int listenfd, short event, void *bula)
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;
event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: engine.c,v 1.98 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: engine.c,v 1.99 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@ -396,7 +396,9 @@ engine(int debug, int verbose)
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = engine_dispatch_main;
/* Setup event handlers. */
@ -673,7 +675,8 @@ engine_dispatch_main(int fd, short event, void *bula)
if (iev_frontend == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, fd);
if (imsgbuf_init(&iev_frontend->ibuf, fd) == -1)
fatal(NULL);
iev_frontend->handler = engine_dispatch_frontend;
iev_frontend->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: frontend.c,v 1.73 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: frontend.c,v 1.74 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@ -179,7 +179,9 @@ frontend(int debug, int verbose)
/* Setup pipe and event handler to the parent process. */
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = frontend_dispatch_main;
iev_main->events = EV_READ;
event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
@ -327,7 +329,8 @@ frontend_dispatch_main(int fd, short event, void *bula)
if (iev_engine == NULL)
fatal(NULL);
imsgbuf_init(&iev_engine->ibuf, fd);
if (imsgbuf_init(&iev_engine->ibuf, fd) == -1)
fatal(NULL);
iev_engine->handler = frontend_dispatch_engine;
iev_engine->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: slaacd.c,v 1.78 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: slaacd.c,v 1.79 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@ -230,9 +230,13 @@ main(int argc, char *argv[])
if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
(iev_engine = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
if (imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_frontend->ibuf);
iev_frontend->handler = main_dispatch_frontend;
imsgbuf_init(&iev_engine->ibuf, pipe_main2engine[0]);
if (imsgbuf_init(&iev_engine->ibuf, pipe_main2engine[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_engine->ibuf);
iev_engine->handler = main_dispatch_engine;
/* Setup event handlers for pipes to engine & frontend. */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.22 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: control.c,v 1.23 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -156,7 +156,12 @@ control_accept(int listenfd, short event, void *bula)
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;
event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events, c->iev.handler,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: frontend.c,v 1.88 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: frontend.c,v 1.89 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@ -233,7 +233,9 @@ frontend(int debug, int verbose)
fatal("iev_main");
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = frontend_dispatch_main;
iev_main->events = EV_READ;
event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
@ -355,7 +357,8 @@ frontend_dispatch_main(int fd, short event, void *bula)
if (iev_resolver == NULL)
fatal(NULL);
imsgbuf_init(&iev_resolver->ibuf, fd);
if (imsgbuf_init(&iev_resolver->ibuf, fd) == -1)
fatal(NULL);
iev_resolver->handler = frontend_dispatch_resolver;
iev_resolver->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: resolver.c,v 1.172 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: resolver.c,v 1.173 2024/11/21 13:35:20 claudio Exp $ */
/*
@ -415,7 +415,9 @@ resolver(int debug, int verbose)
if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_main->ibuf, 3);
if (imsgbuf_init(&iev_main->ibuf, 3) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_main->ibuf);
iev_main->handler = resolver_dispatch_main;
/* Setup event handlers. */
@ -671,7 +673,8 @@ resolver_dispatch_main(int fd, short event, void *bula)
if (iev_frontend == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, fd);
if (imsgbuf_init(&iev_frontend->ibuf, fd) == -1)
fatal(NULL);
iev_frontend->handler = resolver_dispatch_frontend;
iev_frontend->events = EV_READ;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: unwind.c,v 1.74 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: unwind.c,v 1.75 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@ -239,9 +239,13 @@ main(int argc, char *argv[])
if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
(iev_resolver = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
if (imsgbuf_init(&iev_frontend->ibuf, pipe_main2frontend[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_frontend->ibuf);
iev_frontend->handler = main_dispatch_frontend;
imsgbuf_init(&iev_resolver->ibuf, pipe_main2resolver[0]);
if (imsgbuf_init(&iev_resolver->ibuf, pipe_main2resolver[0]) == -1)
fatal(NULL);
imsgbuf_allow_fdpass(&iev_resolver->ibuf);
iev_resolver->handler = main_dispatch_resolver;
/* Setup event handlers for pipes. */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: file.c,v 1.73 2024/11/21 13:24:07 claudio Exp $ */
/* $OpenBSD: file.c,v 1.74 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@ -216,7 +216,9 @@ main(int argc, char **argv)
if (cflag)
goto wait_for_child;
imsgbuf_init(&ibuf, pair[0]);
if (imsgbuf_init(&ibuf, pair[0]) == -1)
err(1, "imsgbuf_init");
imsgbuf_allow_fdpass(&ibuf);
for (idx = 0; idx < argc; idx++) {
fd = prepare_message(&msg, idx, argv[idx]);
send_message(&ibuf, &msg, sizeof msg, fd);
@ -400,7 +402,9 @@ child(int fd, pid_t parent, int argc, char **argv)
width = len;
}
imsgbuf_init(&ibuf, fd);
if (imsgbuf_init(&ibuf, fd) == -1)
err(1, "imsgbuf_init");
imsgbuf_allow_fdpass(&ibuf);
for (;;) {
if (read_message(&ibuf, &imsg, parent) == 0)
break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: proc.c,v 1.29 2024/11/21 13:21:34 claudio Exp $ */
/* $OpenBSD: proc.c,v 1.30 2024/11/21 13:35:20 claudio Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -305,7 +305,9 @@ proc_add_peer(struct tmuxproc *tp, int fd,
peer->dispatchcb = dispatchcb;
peer->arg = arg;
imsgbuf_init(&peer->ibuf, fd);
if (imsgbuf_init(&peer->ibuf, fd) == -1)
fatal("imsgbuf_init");
imsgbuf_allow_fdpass(&peer->ibuf);
event_set(&peer->event, fd, EV_READ, proc_event_cb, peer);
if (getpeereid(fd, &peer->uid, &gid) != 0)