fix: harden the per-user IPC endpoint

This commit is contained in:
2026-08-12 16:08:23 +09:00
parent 4120f90736
commit 432df3730c
9 changed files with 96 additions and 46 deletions

17
srv.c
View File

@@ -1,7 +1,10 @@
#include "dat.h"
#include "fn.h"
static char adir[40];
#include <sys/stat.h>
#include <sys/un.h>
static char adir[256];
static Channel *clientc;
typedef struct Client Client;
@@ -71,12 +74,16 @@ clientthread(void *arg)
static void
srvinit(void)
{
char addr[64];
char addr[128], path[sizeof(((struct sockaddr_un*)0)->sun_path)];
snprint(addr, sizeof(addr), "unix!" IPCPATH, getuid());
remove(addr + 5);
if(ipcpath(path, sizeof path) < 0)
die("IPC path is too long");
if(snprint(addr, sizeof addr, "unix!%s", path) >= (int)sizeof addr)
die("IPC address is too long");
if(announce(addr, adir) < 0)
die("announce: %r");
die("IPC endpoint is already in use: %r");
if(chmod(path, 0600) < 0)
die("can't protect IPC endpoint: %s", path);
}
void