aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2025-11-17 16:15:34 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2025-11-17 16:15:34 -0500
commit7fafed2c89c96d94f43c7253ad7182821ecfbac8 (patch)
treec0474389d51bb5121c884f7626ea90d8a2d862a9
parent76919bc69006fd799fe5c3c979ed4e28e0a09092 (diff)
downloadstasis-7fafed2c89c96d94f43c7253ad7182821ecfbac8.tar.gz
Enforce maximum buffer length of `name`semaphore
-rw-r--r--src/lib/core/semaphore.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/core/semaphore.c b/src/lib/core/semaphore.c
index 6a24726..bfe34e2 100644
--- a/src/lib/core/semaphore.c
+++ b/src/lib/core/semaphore.c
@@ -9,7 +9,14 @@
#include "utils.h"
int semaphore_init(struct Semaphore *s, const char *name, const int value) {
- snprintf(s->name, sizeof(s->name), "/%s", name);
+#if defined(STASIS_OS_DARWIN)
+ // see: sem_open(2)
+ const size_t max_namelen = PSEMNAMLEN;
+#else
+ // see: sem_open(3)
+ const size_t max_namelen = STASIS_NAME_MAX - 4;
+#endif
+ snprintf(s->name, max_namelen, "/%s", name);
s->sem = sem_open(s->name, O_CREAT, 0644, value);
if (s->sem == SEM_FAILED) {
return -1;