Fix matching of message queues by name.

The mqfs_search() routine uses strncmp() to match message queue objects
by name. This is because it can be called from environments where the
file name is not null terminated (the VFS for example).

Unfortunately it doesn't compare the lengths of the message queue names,
which means if a system has "Queue12345", the name "Queue" will also
match.

I noticed this when a student of mine handed in an exercise using
message queues with names "Queue2" and "Queue".

Reviewed by:	rink
This commit is contained in:
Ed Schouten 2008-11-28 14:53:18 +00:00
parent 3b6fe5fcd9
commit 1cbae70533

View File

@ -793,7 +793,8 @@ mqfs_search(struct mqfs_node *pd, const char *name, int len)
sx_assert(&pd->mn_info->mi_lock, SX_LOCKED);
LIST_FOREACH(pn, &pd->mn_children, mn_sibling) {
if (strncmp(pn->mn_name, name, len) == 0)
if (strncmp(pn->mn_name, name, len) == 0 &&
pn->mn_name[len] == '\0')
return (pn);
}
return (NULL);