mirror of
git://git.musl-libc.org/musl
synced 2025-01-31 11:01:34 +00:00
semctl: fix UB causing crashes on powerpc
it's UB to fetch variadic args when none are passed, and this caused real crashes on ppc due to its calling convention, which defines that for variadic functions aggregate types be passed as pointers. the assignment caused that pointer to get dereferenced, resulting in a crash.
This commit is contained in:
parent
7673acd315
commit
2b47a7aff2
@ -11,11 +11,15 @@ union semun {
|
||||
|
||||
int semctl(int id, int num, int cmd, ...)
|
||||
{
|
||||
union semun arg;
|
||||
union semun arg = {0};
|
||||
va_list ap;
|
||||
va_start(ap, cmd);
|
||||
arg = va_arg(ap, union semun);
|
||||
va_end(ap);
|
||||
switch (cmd) {
|
||||
case SETVAL: case GETALL: case SETALL: case IPC_STAT: case IPC_SET:
|
||||
case IPC_INFO: case SEM_INFO: case SEM_STAT:
|
||||
va_start(ap, cmd);
|
||||
arg = va_arg(ap, union semun);
|
||||
va_end(ap);
|
||||
}
|
||||
#ifdef SYS_semctl
|
||||
return syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf);
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user