diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index 7ba1a7cb9fd..b7b8e9862d5 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -103,6 +103,21 @@ FAR sem_t *sem_open(FAR const char *name, int oflags, ...) DEBUGASSERT(name != NULL); + if (name[0] == '/') + { + if (strlen(name) >= PATH_MAX) + { + set_errno(ENAMETOOLONG); + return SEM_FAILED; + } + + if (strlen(strrchr(name, '/') + 1) >= NAME_MAX) + { + set_errno(ENAMETOOLONG); + return SEM_FAILED; + } + } + /* The POSIX specification requires that the "check for the existence * of a semaphore and the creation of the semaphore if it does not * exist shall be atomic with respect to other processes executing