fix: harden the per-user IPC endpoint
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
@@ -21,3 +25,29 @@ ipc_masks_modifiers(struct ct *t)
|
||||
CT_EQ_UINT(t, 0, key);
|
||||
CT_CHECK(t, ipcreqreset(buf));
|
||||
}
|
||||
|
||||
void
|
||||
ipc_runtime_path(struct ct *t)
|
||||
{
|
||||
char buf[128], fallback[128], *old, *saved;
|
||||
|
||||
old = getenv("XDG_RUNTIME_DIR");
|
||||
saved = old == nil ? nil : strdup(old);
|
||||
setenv("XDG_RUNTIME_DIR", "/tmp/strans-runtime-test", 1);
|
||||
CT_EQ_INT(t, 0, ipcpath(buf, sizeof buf));
|
||||
CT_EQ_STR(t, "/tmp/strans-runtime-test/strans.sock", buf);
|
||||
setenv("XDG_RUNTIME_DIR", "/tmp/strans-runtime-test/", 1);
|
||||
CT_EQ_INT(t, 0, ipcpath(buf, sizeof buf));
|
||||
CT_EQ_STR(t, "/tmp/strans-runtime-test/strans.sock", buf);
|
||||
setenv("XDG_RUNTIME_DIR", "relative", 1);
|
||||
CT_EQ_INT(t, 0, ipcpath(buf, sizeof buf));
|
||||
snprint(fallback, sizeof fallback, "/tmp/strans.%d", getuid());
|
||||
CT_EQ_STR(t, fallback, buf);
|
||||
CT_EQ_INT(t, -1, ipcpath(buf, 4));
|
||||
CT_EQ_INT(t, -1, ipcpath(nil, sizeof buf));
|
||||
if(saved != nil){
|
||||
setenv("XDG_RUNTIME_DIR", saved, 1);
|
||||
free(saved);
|
||||
}else
|
||||
unsetenv("XDG_RUNTIME_DIR");
|
||||
}
|
||||
|
||||
@@ -64,5 +64,6 @@ void dictionary_candidates(struct ct*);
|
||||
void dictionary_misses_clear_result(struct ct*);
|
||||
void dictionary_emoji_identity(struct ct*);
|
||||
void ipc_masks_modifiers(struct ct*);
|
||||
void ipc_runtime_path(struct ct*);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -113,6 +113,7 @@ static const struct ct_test tests[] = {
|
||||
{ "dict/misses-clear-result", dictionary_misses_clear_result },
|
||||
{ "dict/emoji-identity", dictionary_emoji_identity },
|
||||
{ "ipc/masks-modifiers", ipc_masks_modifiers },
|
||||
{ "ipc/runtime-path", ipc_runtime_path },
|
||||
};
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user