[PATCH 3/6] sysvipc: Fix IPC_INFO and MSG_INFO handling [BZ #26639]
Florian Weimer
fweimer@redhat.com
Tue Sep 29 07:57:10 GMT 2020
* Adhemerval Zanella via Libc-alpha:
> +static int
> +read_proc_file (const char *file)
> +{
> + FILE *f = fopen (file, "r");
> + if (f == NULL)
> + return -1;
> +
> + int v;
> + int r = fscanf (f, "%d", & v);
> + TEST_VERIFY_EXIT (r == 1);
> +
> + fclose (f);
> + return v;
> +}
You could use xfopen and xfclose.
> +/* Check if the message queue with IDX (index into the kernel's internal
> + array) matches the one with KEY. The CMD is either MSG_STAT or
> + MSG_STAT_ANY. */
> +
> +static bool
> +check_msginfo (int idx, key_t key, int cmd)
> +{
> + struct msqid_ds msginfo;
> + int mid = msgctl (idx, cmd, &msginfo);
> + /* Ignore unused array slot returned by the kernel or information from
> + unknown message queue. */
> + if ((mid == -1 && errno == EINVAL) || mid != msqid)
> + return false;
> +
> + if (mid == -1)
> + FAIL_EXIT1 ("msgctl with %s failed: %m",
> + cmd == MSG_STAT ? "MSG_STAT" : "MSG_STAT_ANY");
> +
> + if (msginfo.msg_perm.__key != key)
> + FAIL_EXIT1 ("msgid_ds::msg_perm::key (%d) != %d",
> + (int) msginfo.msg_perm.__key, (int) key);
> + if (msginfo.msg_perm.mode != MSGQ_MODE)
> + FAIL_EXIT1 ("msgid_ds::msg_perm::mode (%o) != %o",
> + msginfo.msg_perm.mode, MSGQ_MODE);
> + if (msginfo.msg_qnum != 0)
> + FAIL_EXIT1 ("msgid_ds::msg_qnum (%lu) != 0",
> + (long unsigned) msginfo.msg_qnum);
As in the other patch, you might want to use TEST_COMPARE here.
Rest looks okay, I think.
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