[PATCH 1/6] sysvipc: Fix SEM_STAT_ANY kernel argument pass [BZ #26637]
Florian Weimer
fweimer@redhat.com
Mon Sep 28 14:59:28 GMT 2020
* Adhemerval Zanella via Libc-alpha:
> +/* Check if the semaphore with IDX (index into the kernel's internal array)
> + matches the one with KEY. The CMD is either SEM_STAT or SEM_STAT_ANY. */
> +
> +static bool
> +check_seminfo (int idx, key_t key, int cmd)
> +{
> + struct semid_ds seminfo;
> + int sid = semctl (idx, 0, cmd, (union semun) { .buf = &seminfo });
> + /* Ignore unused array slot returned by the kernel or information from
> + unknown semaphores. */
> + if ((sid == -1 && errno == EINVAL) || sid != semid)
> + return false;
> +
> + if (sid == -1)
> + FAIL_EXIT1 ("semctl with SEM_STAT failed (errno=%d)", errno);
> +
> + if (seminfo.sem_perm.__key != key)
> + FAIL_EXIT1 ("semid_ds::sem_perm::key (%d) != %d",
> + (int) seminfo.sem_perm.__key, (int) key);
> + if (seminfo.sem_perm.mode != SEM_MODE)
> + FAIL_EXIT1 ("semid_ds::sem_perm::mode (%o) != %o",
> + seminfo.sem_perm.mode, SEM_MODE);
> + if (seminfo.sem_nsems != 1)
> + FAIL_EXIT1 ("semid_ds::sem_nsems (%lu) != 1",
> + (long unsigned) seminfo.sem_nsems);
> +
> + return true;
> +}
Did you mean to include idx in the FAIL_EXIT1 output? Otherwise you
could use TEST_COMPARE here?
> diff --git a/sysvipc/test-sysvsem.c b/sysvipc/test-sysvsem.c
> index 01dbff343a..b7284e0b48 100644
> --- a/sysvipc/test-sysvsem.c
> +++ b/sysvipc/test-sysvsem.c
> @@ -20,6 +20,7 @@
> #include <stdlib.h>
> #include <errno.h>
> #include <string.h>
> +#include <stdbool.h>
> #include <sys/types.h>
> #include <sys/ipc.h>
> #include <sys/sem.h>
Stray change?
Rest looks okay to me.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
More information about the Libc-alpha
mailing list