From: Roy Marples Date: Sat, 15 Jun 2024 09:04:06 +0000 (+0100) Subject: privsep: Allow zero length messages through X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53e2f6de4ba87d0534c89cae674e6c1a48724ef0;p=thirdparty%2Fdhcpcd.git privsep: Allow zero length messages through They should be handled gracefully without privsep anyway. Fix for #179. --- diff --git a/src/privsep-inet.c b/src/privsep-inet.c index 3a192ee0..7f7494f6 100644 --- a/src/privsep-inet.c +++ b/src/privsep-inet.c @@ -53,7 +53,7 @@ ps_inet_recvbootp(void *arg) { struct dhcpcd_ctx *ctx = arg; - if (ps_recvmsg(ctx, ctx->udp_rfd, PS_BOOTP, ctx->ps_inet_fd) == -1) + if (ps_recvmsg(ctx->udp_rfd, PS_BOOTP, ctx->ps_inet_fd) == -1) logerr(__func__); } #endif @@ -67,12 +67,12 @@ ps_inet_recvra(void *arg) struct rs_state *state = RS_STATE(ifp); struct dhcpcd_ctx *ctx = ifp->ctx; - if (ps_recvmsg(ctx, state->nd_fd, PS_ND, ctx->ps_inet_fd) == -1) + if (ps_recvmsg(state->nd_fd, PS_ND, ctx->ps_inet_fd) == -1) logerr(__func__); #else struct dhcpcd_ctx *ctx = arg; - if (ps_recvmsg(ctx, ctx->nd_fd, PS_ND, ctx->ps_inet_fd) == -1) + if (ps_recvmsg(ctx->nd_fd, PS_ND, ctx->ps_inet_fd) == -1) logerr(__func__); #endif } @@ -84,7 +84,7 @@ ps_inet_recvdhcp6(void *arg) { struct dhcpcd_ctx *ctx = arg; - if (ps_recvmsg(ctx, ctx->dhcp6_rfd, PS_DHCP6, ctx->ps_inet_fd) == -1) + if (ps_recvmsg(ctx->dhcp6_rfd, PS_DHCP6, ctx->ps_inet_fd) == -1) logerr(__func__); } #endif @@ -374,7 +374,7 @@ ps_inet_recvinbootp(void *arg) { struct ps_process *psp = arg; - if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, + if (ps_recvmsg(psp->psp_work_fd, PS_BOOTP, psp->psp_ctx->ps_data_fd) == -1) logerr(__func__); } @@ -463,7 +463,7 @@ ps_inet_recvin6dhcp6(void *arg) { struct ps_process *psp = arg; - if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, + if (ps_recvmsg(psp->psp_work_fd, PS_DHCP6, psp->psp_ctx->ps_data_fd) == -1) logerr(__func__); } diff --git a/src/privsep.c b/src/privsep.c index ab29bb7b..0f78907a 100644 --- a/src/privsep.c +++ b/src/privsep.c @@ -897,7 +897,7 @@ nobufs: } ssize_t -ps_recvmsg(struct dhcpcd_ctx *ctx, int rfd, uint16_t cmd, int wfd) +ps_recvmsg(int rfd, uint16_t cmd, int wfd) { struct sockaddr_storage ss = { .ss_family = AF_UNSPEC }; uint8_t controlbuf[sizeof(struct sockaddr_storage)] = { 0 }; @@ -913,24 +913,15 @@ ps_recvmsg(struct dhcpcd_ctx *ctx, int rfd, uint16_t cmd, int wfd) ssize_t len = recvmsg(rfd, &msg, 0); - if (len == -1) + if (len == -1) { logerr("%s: recvmsg", __func__); - if (len == -1 || len == 0) { - if (ctx->options & DHCPCD_FORKED && - !(ctx->options & DHCPCD_PRIVSEPROOT)) - eloop_exit(ctx->eloop, - len == 0 ? EXIT_SUCCESS : EXIT_FAILURE); return len; } iov[0].iov_len = (size_t)len; len = ps_sendcmdmsg(wfd, cmd, &msg); - if (len == -1) { + if (len == -1) logerr("ps_sendcmdmsg"); - if (ctx->options & DHCPCD_FORKED && - !(ctx->options & DHCPCD_PRIVSEPROOT)) - eloop_exit(ctx->eloop, EXIT_FAILURE); - } return len; } diff --git a/src/privsep.h b/src/privsep.h index 132f679a..00184d07 100644 --- a/src/privsep.h +++ b/src/privsep.h @@ -192,7 +192,7 @@ ssize_t ps_sendmsg(struct dhcpcd_ctx *, int, uint16_t, unsigned long, const struct msghdr *); ssize_t ps_sendcmd(struct dhcpcd_ctx *, int, uint16_t, unsigned long, const void *data, size_t len); -ssize_t ps_recvmsg(struct dhcpcd_ctx *, int, uint16_t, int); +ssize_t ps_recvmsg(int, uint16_t, int); ssize_t ps_recvpsmsg(struct dhcpcd_ctx *, int, ssize_t (*callback)(void *, struct ps_msghdr *, struct msghdr *), void *);