From 368b5fc1554d20db1ce11c89b1ea6b8ed2d07a0a Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Wed, 23 Mar 2016 11:11:30 +0530 Subject: [PATCH] Initialise the "name" variable properly and compare all 32 bytes Without this patch, calling sys_mq_open() with same names specified results in two separate queues being opened and their descriptors returned instead of the same descriptor being returned for both. Do the initialisation and comparison properly, so that when the same name is specified to sys_mq_open multiple times in same process or different process, the same opened queue descriptor is returned. --- minix/kernel/mqueue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/minix/kernel/mqueue.c b/minix/kernel/mqueue.c index 4b8e050d2..748029837 100644 --- a/minix/kernel/mqueue.c +++ b/minix/kernel/mqueue.c @@ -80,7 +80,7 @@ int mq_open(const char *name, int oflag) for (int i = 0; i < number_of_queues; i++) if (mq.queue_slot_empty[i] == NOT_EMPTY) - if (strcmp(mq.msg[i].name, name) == 0) { + if (strncmp(mq.msg[i].name, name, NAME_SIZE) == 0) { mq.msg[i].num_users++; return (mqd_t) i; } @@ -91,6 +91,7 @@ int mq_open(const char *name, int oflag) mq.queue_slot_empty[i] = NOT_EMPTY; mq.num_queues++; mq.msg[i].num_users++; + memset(mq.msg[i].name, '\0', NAME_SIZE); strncpy(mq.msg[i].name, name, strlen(name)); for (int j = 0; j < number_of_messages; j++) {