]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Only unlink control sockets if we created them
authorRoy Marples <roy@marples.name>
Sun, 2 Jul 2023 00:28:34 +0000 (01:28 +0100)
committerRoy Marples <roy@marples.name>
Sun, 2 Jul 2023 00:28:34 +0000 (01:28 +0100)
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

index 3de8bf91f92d8b140b079949f67f843cbded238b..5325ac35095330844e7e52b8a1c6c5a12f0d9600 100644 (file)
@@ -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)