summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 13:43:11 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 13:43:11 +0000
commitc623ed1033486d6bd76332714e1cfd31c2d5cce5 (patch)
tree0f52409dc8a29266314b5cf8952251584422d9ee
parent843a735af0128d99b24d97af1ab2cea78a17cca0 (diff)
Handle radiusd and npppd, they are different but nothing stands out.
OK tb@
-rw-r--r--usr.sbin/npppctl/npppctl.c5
-rw-r--r--usr.sbin/npppd/npppd/control.c11
-rw-r--r--usr.sbin/npppd/npppd/privsep.c11
-rw-r--r--usr.sbin/radiusctl/radiusctl.c5
-rw-r--r--usr.sbin/radiusd/control.c9
-rw-r--r--usr.sbin/radiusd/radiusd.c7
-rw-r--r--usr.sbin/radiusd/radiusd_bsdauth.c8
-rw-r--r--usr.sbin/radiusd/radiusd_file.c8
-rw-r--r--usr.sbin/radiusd/radiusd_module.c7
9 files changed, 50 insertions, 21 deletions
diff --git a/usr.sbin/npppctl/npppctl.c b/usr.sbin/npppctl/npppctl.c
index 5ed59dc25c5..84c8b243e64 100644
--- a/usr.sbin/npppctl/npppctl.c
+++ b/usr.sbin/npppctl/npppctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: npppctl.c,v 1.14 2024/11/21 13:23:13 claudio Exp $ */
+/* $OpenBSD: npppctl.c,v 1.15 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2012 Internet Initiative Japan Inc.
@@ -108,7 +108,8 @@ main(int argc, char *argv[])
if (connect(ctlsock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
err(EXIT_FAILURE, "connect");
- imsgbuf_init(&ctl_ibuf, ctlsock);
+ if (imsgbuf_init(&ctl_ibuf, ctlsock) == -1)
+ err(EXIT_FAILURE, "imsgbuf_init");
switch (result->action) {
case SESSION_BRIEF:
diff --git a/usr.sbin/npppd/npppd/control.c b/usr.sbin/npppd/npppd/control.c
index 710dc50933d..42133583ecf 100644
--- a/usr.sbin/npppd/npppd/control.c
+++ b/usr.sbin/npppd/npppd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.14 2024/11/21 13:23:13 claudio Exp $ */
+/* $OpenBSD: control.c,v 1.15 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -181,13 +181,20 @@ control_accept(int listenfd, short event, void *arg)
return;
}
if ((c->ctx = npppd_ctl_create(cs->cs_ctx)) == NULL) {
+ log_warn("control_accept");
+ close(connfd);
free(c);
+ return;
+ }
+
+ if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) {
log_warn("control_accept");
close(connfd);
+ free(c->ctx);
+ free(c);
return;
}
- imsgbuf_init(&c->iev.ibuf, connfd);
c->iev.handler = control_dispatch_imsg;
c->iev.events = EV_READ;
c->iev.data = cs;
diff --git a/usr.sbin/npppd/npppd/privsep.c b/usr.sbin/npppd/npppd/privsep.c
index 833a3f062ff..e2304d907ee 100644
--- a/usr.sbin/npppd/npppd/privsep.c
+++ b/usr.sbin/npppd/npppd/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.28 2024/11/21 13:23:13 claudio Exp $ */
+/* $OpenBSD: privsep.c,v 1.29 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2010 Yasuoka Masahiko <yasuoka@openbsd.org>
@@ -37,6 +37,7 @@
#include "npppd.h"
#include "ppp.h"
+#include "log.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@@ -191,7 +192,9 @@ privsep_init(void)
close(pairsock[0]);
privsep_sock = pairsock[1];
privsep_pid = pid;
- imsgbuf_init(&privsep_ibuf, privsep_sock);
+ if (imsgbuf_init(&privsep_ibuf, privsep_sock) == -1)
+ goto fail;
+ imsgbuf_allow_fdpass(&privsep_ibuf);
return (0);
/* NOTREACHED */
@@ -565,7 +568,9 @@ privsep_priv_main(int sock)
{
struct imsgbuf ibuf;
- imsgbuf_init(&ibuf, sock);
+ if (imsgbuf_init(&ibuf, sock) == -1)
+ fatal("imsgbuf_init");
+ imsgbuf_allow_fdpass(&ibuf);
privsep_priv_dispatch_imsg(&ibuf);
imsgbuf_clear(&ibuf);
close(sock);
diff --git a/usr.sbin/radiusctl/radiusctl.c b/usr.sbin/radiusctl/radiusctl.c
index 14eec580921..b1865362bf0 100644
--- a/usr.sbin/radiusctl/radiusctl.c
+++ b/usr.sbin/radiusctl/radiusctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radiusctl.c,v 1.16 2024/11/21 13:23:37 claudio Exp $ */
+/* $OpenBSD: radiusctl.c,v 1.17 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
*
@@ -147,7 +147,8 @@ main(int argc, char *argv[])
err(EX_OSERR, "socket");
if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
err(EX_OSERR, "connect");
- imsgbuf_init(&ibuf, sock);
+ if (imsgbuf_init(&ibuf, sock) == -1)
+ err(EX_OSERR, "imsgbuf_init");
res = parse(argc, argv);
if (res == NULL)
diff --git a/usr.sbin/radiusd/control.c b/usr.sbin/radiusd/control.c
index 4af7e56c281..5b069d109df 100644
--- a/usr.sbin/radiusd/control.c
+++ b/usr.sbin/radiusd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.6 2024/11/21 13:23:37 claudio Exp $ */
+/* $OpenBSD: control.c,v 1.7 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -165,10 +165,15 @@ control_accept(int listenfd, short event, void *bula)
return;
}
+ if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) {
+ log_warn("control_accept");
+ close(connfd);
+ free(c);
+ return;
+ }
if (idseq == 0) /* don't use zero. See radiusd_module_imsg */
++idseq;
c->id = idseq++;
- imsgbuf_init(&c->iev.ibuf, connfd);
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, c);
diff --git a/usr.sbin/radiusd/radiusd.c b/usr.sbin/radiusd/radiusd.c
index 02bc3d073cb..992bb5a487a 100644
--- a/usr.sbin/radiusd/radiusd.c
+++ b/usr.sbin/radiusd/radiusd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radiusd.c,v 1.60 2024/11/21 13:23:37 claudio Exp $ */
+/* $OpenBSD: radiusd.c,v 1.61 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2013, 2023 Internet Initiative Japan Inc.
@@ -1200,7 +1200,10 @@ radiusd_module_load(struct radiusd *radiusd, const char *path, const char *name)
}
strlcpy(module->name, name, sizeof(module->name));
module->pid = pid;
- imsgbuf_init(&module->ibuf, module->fd);
+ if (imsgbuf_init(&module->ibuf, module->fd) == -1) {
+ log_warn("Could not load module `%s': imsgbuf_init", name);
+ goto on_error;
+ }
if (imsg_sync_read(&module->ibuf, MODULE_IO_TIMEOUT) <= 0 ||
(n = imsg_get(&module->ibuf, &imsg)) <= 0) {
diff --git a/usr.sbin/radiusd/radiusd_bsdauth.c b/usr.sbin/radiusd/radiusd_bsdauth.c
index c1983547fdf..73ec70e2cf0 100644
--- a/usr.sbin/radiusd/radiusd_bsdauth.c
+++ b/usr.sbin/radiusd/radiusd_bsdauth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radiusd_bsdauth.c,v 1.18 2024/11/21 13:23:37 claudio Exp $ */
+/* $OpenBSD: radiusd_bsdauth.c,v 1.19 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -113,7 +113,8 @@ main(int argc, char *argv[])
* Privileged process
*/
setproctitle("[priv]");
- imsgbuf_init(&ibuf, pairsock[0]);
+ if (imsgbuf_init(&ibuf, pairsock[0]) == 1)
+ err(EXIT_FAILURE, "imsgbuf_init");
if (pledge("stdio getpw rpath proc exec", NULL) == -1)
err(EXIT_FAILURE, "pledge");
@@ -250,7 +251,8 @@ module_bsdauth_main(void)
module_drop_privilege(module_bsdauth.base, 0);
module_load(module_bsdauth.base);
- imsgbuf_init(&module_bsdauth.ibuf, 3);
+ if (imsgbuf_init(&module_bsdauth.ibuf, 3) == -1)
+ err(EXIT_FAILURE, "imsgbuf_init");
if (pledge("stdio proc", NULL) == -1)
err(EXIT_FAILURE, "pledge");
diff --git a/usr.sbin/radiusd/radiusd_file.c b/usr.sbin/radiusd/radiusd_file.c
index 9016d9ac46d..c2ec82a6c9b 100644
--- a/usr.sbin/radiusd/radiusd_file.c
+++ b/usr.sbin/radiusd/radiusd_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radiusd_file.c,v 1.7 2024/11/21 13:23:37 claudio Exp $ */
+/* $OpenBSD: radiusd_file.c,v 1.8 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2024 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -128,7 +128,8 @@ main(int argc, char *argv[])
if (pledge("stdio rpath unveil", NULL) == -1)
err(EXIT_FAILURE, "pledge");
setproctitle("[priv]");
- imsgbuf_init(&ibuf, pairsock[0]);
+ if (imsgbuf_init(&ibuf, pairsock[0]) == -1)
+ err(EXIT_FAILURE, "imsgbuf_init");
/* Receive parameters from the main process. */
if (imsg_sync_read(&ibuf, 2000) <= 0 ||
@@ -244,7 +245,8 @@ module_file_main(void)
module_drop_privilege(module_file.base, 0);
module_load(module_file.base);
- imsgbuf_init(&module_file.ibuf, 3);
+ if (imsgbuf_init(&module_file.ibuf, 3) == -1)
+ err(EXIT_FAILURE, "imsgbuf_init");
if (pledge("stdio", NULL) == -1)
err(EXIT_FAILURE, "pledge");
diff --git a/usr.sbin/radiusd/radiusd_module.c b/usr.sbin/radiusd/radiusd_module.c
index b43b871fab9..0c1a09d2018 100644
--- a/usr.sbin/radiusd/radiusd_module.c
+++ b/usr.sbin/radiusd/radiusd_module.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radiusd_module.c,v 1.25 2024/11/21 13:23:37 claudio Exp $ */
+/* $OpenBSD: radiusd_module.c,v 1.26 2024/11/21 13:43:10 claudio Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -95,7 +95,10 @@ module_create(int sock, void *ctx, struct module_handlers *handler)
if ((base = calloc(1, sizeof(struct module_base))) == NULL)
return (NULL);
- imsgbuf_init(&base->ibuf, sock);
+ if (imsgbuf_init(&base->ibuf, sock) == -1) {
+ free(base);
+ return (NULL);
+ }
base->ctx = ctx;
module_userpass = handler->userpass;