Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190428111646.GN26605@port70.net>
Date: Sun, 28 Apr 2019 13:16:46 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] mq_open: Perform check for mq name

* Qiang Huang <h.huangqiang@...wei.com> [2019-04-28 05:31:53 -0400]:
> According to Linux man page:
> [http://man7.org/linux/man-pages/man2/mq_open.2.html]
> 
> ```
> C library/kernel differences
>    The mq_open() library function is implemented on top of a system call
>    of the same name.  The library function performs the check that the
>    name starts with a slash (/), giving the EINVAL error if it does not.
>    The kernel system call expects name to contain no preceding slash, so
>    the C library function passes name without the preceding slash (i.e.,
>    name+1) to the system call.
> ```
> 
> glibc performs the check but musl doesn't, add the
> check so we can have consistent behavior.
> 
> Signed-off-by: Qiang Huang <h.huangqiang@...wei.com>

posix says:

 "If name does not begin with the <slash> character,
  the effect is implementation-defined."

and on linux the documented behaviour is EINVAL, so
the patch looks ok.

> ---
>  src/mq/mq_open.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/mq/mq_open.c b/src/mq/mq_open.c
> index aa91d58..e626228 100644
> --- a/src/mq/mq_open.c
> +++ b/src/mq/mq_open.c
> @@ -1,12 +1,14 @@
>  #include <mqueue.h>
>  #include <fcntl.h>
>  #include <stdarg.h>
> +#include <errno.h>
>  #include "syscall.h"
>  
>  mqd_t mq_open(const char *name, int flags, ...)
>  {
>  	mode_t mode = 0;
>  	struct mq_attr *attr = 0;
> +	if (name[0] != '/') return __syscall_ret(-EINVAL);
>  	if (*name == '/') name++;
>  	if (flags & O_CREAT) {
>  		va_list ap;
> -- 
> 2.7.4

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.