fix: harden the per-user IPC endpoint
This commit is contained in:
17
srv.c
17
srv.c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user