From 327e19a5cce11e0250f086695641b4a3b238ee4f Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sun, 2 Jul 2023 01:28:34 +0100 Subject: [PATCH] privsep: Only unlink control sockets if we created them Fixes a segfault when trying to start dhcpcd as a non root user. Closes #219 without an explicit test for being the root user. --- src/control.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/control.c b/src/control.c index 3de8bf91..5325ac35 100644 --- a/src/control.c +++ b/src/control.c @@ -498,9 +498,11 @@ control_stop(struct dhcpcd_ctx *ctx) #ifdef PRIVSEP if (IN_PRIVSEP_SE(ctx)) { - if (ps_root_unlink(ctx, ctx->control_sock) == -1) + if (ctx->control_sock[0] != '\0' && + ps_root_unlink(ctx, ctx->control_sock) == -1) retval = -1; - if (ps_root_unlink(ctx, ctx->control_sock_unpriv) == -1) + if (ctx->control_sock_unpriv[0] != '\0' && + ps_root_unlink(ctx, ctx->control_sock_unpriv) == -1) retval = -1; return retval; } else if (ctx->options & DHCPCD_FORKED) -- 2.47.3