fix: construct Plan 9 paths without truncation

This commit is contained in:
2026-08-12 17:28:17 +09:00
parent 0d06ba43cd
commit a8a6c3b455
3 changed files with 15 additions and 12 deletions

10
dict.c
View File

@@ -99,16 +99,16 @@ dictopen(char *path)
void
dictinit(char *dir)
{
char path[1024];
char *path;
int i;
for(i = 0; i < nlang; i++){
if(langs[i].dictname == nil)
continue;
if(snprint(path, sizeof(path), "%s/%s.dict", dir,
langs[i].dictname) >= (int)sizeof path)
die("dictionary path too long: %s/%s.dict",
dir, langs[i].dictname);
path = smprint("%s/%s.dict", dir, langs[i].dictname);
if(path == nil)
die("out of memory");
langs[i].dict = dictopen(path);
free(path);
}
}

8
srv.c
View File

@@ -74,14 +74,16 @@ clientthread(void *arg)
static void
srvinit(void)
{
char addr[128], path[sizeof(((struct sockaddr_un*)0)->sun_path)];
char *addr, path[sizeof(((struct sockaddr_un*)0)->sun_path)];
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");
addr = smprint("unix!%s", path);
if(addr == nil)
die("out of memory");
if(announce(addr, adir) < 0)
die("IPC endpoint is already in use: %r");
free(addr);
if(chmod(path, 0600) < 0)
die("can't protect IPC endpoint: %s", path);
}

View File

@@ -860,15 +860,16 @@ mapget(Trie *t, Str *key, Str *out)
void
mapinit(char *dir)
{
char path[1024];
char *path;
int i;
for(i = 0; i < nelem(langs); i++){
if(langs[i].mapname == nil)
continue;
if(snprint(path, sizeof(path), "%s/%s.map", dir,
langs[i].mapname) >= (int)sizeof path)
die("map path too long: %s/%s.map", dir, langs[i].mapname);
path = smprint("%s/%s.map", dir, langs[i].mapname);
if(path == nil)
die("out of memory");
langs[i].map = trieopen(path);
free(path);
}
}