From 3cc21533749d6d8c9c57a10ab6a6ad2723eb3a0d Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 17 Jan 2024 08:22:40 +0000 Subject: [PATCH] Convert to use imsg_get_fd() since proc_forward_imsg() never forwards a file descriptor just use -1 there. OK tb@ --- usr.sbin/httpd/config.c | 17 ++++++++++------- usr.sbin/httpd/logger.c | 6 +++--- usr.sbin/httpd/proc.c | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c index e8c5cd5b6be..b4a8e734d61 100644 --- a/usr.sbin/httpd/config.c +++ b/usr.sbin/httpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.64 2024/01/17 08:20:58 claudio Exp $ */ +/* $OpenBSD: config.c,v 1.65 2024/01/17 08:22:40 claudio Exp $ */ /* * Copyright (c) 2011 - 2015 Reyk Floeter @@ -626,6 +626,7 @@ config_getserver(struct httpd *env, struct imsg *imsg) struct server_config srv_conf; uint8_t *p = imsg->data; size_t s; + int fd; IMSG_SIZE_CHECK(imsg, &srv_conf); memcpy(&srv_conf, p, sizeof(srv_conf)); @@ -634,6 +635,8 @@ config_getserver(struct httpd *env, struct imsg *imsg) /* Reset these variables to avoid free'ing invalid pointers */ serverconfig_reset(&srv_conf); + fd = imsg_get_fd(imsg); + if ((IMSG_DATA_SIZE(imsg) - s) < (size_t)srv_conf.return_uri_len) { log_debug("%s: invalid message length", __func__); goto fail; @@ -643,11 +646,11 @@ config_getserver(struct httpd *env, struct imsg *imsg) if ((srv = server_byaddr((struct sockaddr *) &srv_conf.ss, srv_conf.port)) != NULL) { /* Add "host" to existing listening server */ - if (imsg->fd != -1) { + if (fd != -1) { if (srv->srv_s == -1) - srv->srv_s = imsg->fd; + srv->srv_s = fd; else - close(imsg->fd); + close(fd); } return (config_getserver_config(env, srv, imsg)); } @@ -660,7 +663,7 @@ config_getserver(struct httpd *env, struct imsg *imsg) goto fail; memcpy(&srv->srv_conf, &srv_conf, sizeof(srv->srv_conf)); - srv->srv_s = imsg->fd; + srv->srv_s = fd; if (config_getserver_auth(env, &srv->srv_conf) != 0) goto fail; @@ -688,8 +691,8 @@ config_getserver(struct httpd *env, struct imsg *imsg) return (0); fail: - if (imsg->fd != -1) - close(imsg->fd); + if (fd != -1) + close(fd); if (srv != NULL) serverconfig_free(&srv->srv_conf); free(srv); diff --git a/usr.sbin/httpd/logger.c b/usr.sbin/httpd/logger.c index 9c62485e022..31f441011ab 100644 --- a/usr.sbin/httpd/logger.c +++ b/usr.sbin/httpd/logger.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logger.c,v 1.24 2021/01/27 07:21:53 deraadt Exp $ */ +/* $OpenBSD: logger.c,v 1.25 2024/01/17 08:22:40 claudio Exp $ */ /* * Copyright (c) 2014 Reyk Floeter @@ -144,9 +144,9 @@ logger_open_fd(struct imsg *imsg) TAILQ_FOREACH(log, &log_files, log_entry) { if (log->log_id == id) { + log->log_fd = imsg_get_fd(imsg); DPRINTF("%s: received log fd %d, file %s", - __func__, imsg->fd, log->log_name); - log->log_fd = imsg->fd; + __func__, log->log_fd, log->log_name); return (0); } } diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c index 71bb3c287db..e8b08dd2317 100644 --- a/usr.sbin/httpd/proc.c +++ b/usr.sbin/httpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.42 2023/02/15 20:44:01 tobhe Exp $ */ +/* $OpenBSD: proc.c,v 1.43 2024/01/17 08:22:40 claudio Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -668,7 +668,7 @@ proc_dispatch(int fd, short event, void *arg) case IMSG_CTL_PROCFD: IMSG_SIZE_CHECK(&imsg, &pf); memcpy(&pf, imsg.data, sizeof(pf)); - proc_accept(ps, imsg.fd, pf.pf_procid, + proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid, pf.pf_instance); break; default: @@ -799,7 +799,7 @@ proc_forward_imsg(struct privsep *ps, struct imsg *imsg, enum privsep_procid id, int n) { return (proc_compose_imsg(ps, id, n, imsg->hdr.type, - imsg->hdr.peerid, imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg))); + imsg->hdr.peerid, -1, imsg->data, IMSG_DATA_SIZE(imsg))); } struct imsgbuf * -- 2.20.1