libandroid-posix-semaphore: Fix hardcoded string lengths

This commit is contained in:
Tee KOBAYASHI 2022-02-12 13:40:04 +09:00 committed by Henrik Grimler
parent 38ffdd9187
commit 7c375fd144
No known key found for this signature in database
GPG Key ID: B0076E490B71616B
2 changed files with 6 additions and 4 deletions

View File

@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Shared library for the posix semaphore system function"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.1
TERMUX_PKG_REVISION=1
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_BUILD_IN_SRC=true

View File

@ -46,6 +46,7 @@
#ifndef PREFIX
#define PREFIX "/data/data/com.termux/files/usr"
#endif
#define SEM_PREFIX PREFIX"/tmp/sem."
static __inline__ char *__strchrnul(const char *s, int c)
{
@ -82,8 +83,8 @@ static char *__sem_mapname(const char *name, char *buf)
errno = ENAMETOOLONG;
return 0;
}
memcpy(buf, PREFIX"/tmp/sem.", 40);
memcpy(buf+40, name, p-name+1);
memcpy(buf, SEM_PREFIX, strlen(SEM_PREFIX));
memcpy(buf+strlen(SEM_PREFIX), name, p-name+1);
return buf;
}
@ -96,7 +97,7 @@ sem_t *sem_open(const char *name, int flags, ...)
sem_t newsem;
void *map;
struct stat st;
char buf[NAME_MAX+41];
char buf[NAME_MAX+strlen(SEM_PREFIX)+1];
if (!(name = __sem_mapname(name, buf)))
return SEM_FAILED;
@ -242,7 +243,7 @@ int sem_close(sem_t *sem)
int sem_unlink(const char *name)
{
char buf[NAME_MAX+41];
char buf[NAME_MAX+strlen(SEM_PREFIX)+1];
if (!(name = __sem_mapname(name, buf))) return -1;
return unlink(name);
}