mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] mq_open: Perform check for mq name
@ 2019-04-28  9:31 Qiang Huang
  2019-04-28 11:16 ` Szabolcs Nagy
  0 siblings, 1 reply; 2+ messages in thread
From: Qiang Huang @ 2019-04-28  9:31 UTC (permalink / raw)
  To: musl

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@huawei.com>
---
 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mq_open: Perform check for mq name
  2019-04-28  9:31 [PATCH] mq_open: Perform check for mq name Qiang Huang
@ 2019-04-28 11:16 ` Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2019-04-28 11:16 UTC (permalink / raw)
  To: musl

* Qiang Huang <h.huangqiang@huawei.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@huawei.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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-28 11:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28  9:31 [PATCH] mq_open: Perform check for mq name Qiang Huang
2019-04-28 11:16 ` Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).