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

View File

@@ -2,8 +2,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
#include <xcb-imdkit/imdkit.h>
@@ -119,22 +117,11 @@ srvclose(Ic *state)
static int
srvconnect(Ic *state)
{
struct sockaddr_un addr;
int fd;
if(state->fd >= 0)
return 0;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if(fd < 0)
state->fd = ipcconnect();
if(state->fd < 0)
return -1;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
snprintf(addr.sun_path, sizeof(addr.sun_path), IPCPATH, getuid());
if(connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0){
close(fd);
return -1;
}
state->fd = fd;
return 0;
}