diff mbox series

msgrcv02: Add negative msgtyp tests

Message ID 20211012092858.29992-1-rpalethorpe@suse.com
State Accepted
Headers show
Series msgrcv02: Add negative msgtyp tests | expand

Commit Message

Richard Palethorpe Oct. 12, 2021, 9:28 a.m. UTC
Test that we do not get higher message types. Also that -1 msgtyp is not
misinterpreted as INT_MAX by using MSG_EXCEPT.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
---
 .../kernel/syscalls/ipc/msgrcv/msgrcv02.c     | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Yang Xu \(Fujitsu\) Oct. 13, 2021, 8:24 a.m. UTC | #1
Hi Richard
> Test that we do not get higher message types. Also that -1 msgtyp is not
> misinterpreted as INT_MAX by using MSG_EXCEPT.

Other than some unnecessary spaces or empty lines, this patch looks good 
to me.

Reviewed-by: Yang Xu <xuyang2018.jy@fujitsu.com>

Best Regards
Yang Xu
>
> Signed-off-by: Richard Palethorpe<rpalethorpe@suse.com>
> Suggested-by: Cyril Hrubis<chrubis@suse.cz>
> ---
>   .../kernel/syscalls/ipc/msgrcv/msgrcv02.c     | 19 ++++++++++++-------
>   1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> index cfb7d7446..fba6a5289 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> @@ -21,6 +21,8 @@
>    *   msgflg and no message of the requested type existed on the message queue.
>    */
>
> +#define _GNU_SOURCE
> +
>   #include<string.h>
>   #include<sys/wait.h>
>   #include<sys/msg.h>
> @@ -38,7 +40,7 @@ struct passwd *pw;
>   static struct buf {
>   	long type;
>   	char mtext[MSGSIZE];
> -} rcv_buf, snd_buf = {MSGTYPE, "hello"};
> +} rcv_buf, snd_buf = {2, "hello"};
>
>   static struct tcase {
>   	int *id;
> @@ -49,12 +51,15 @@ static struct tcase {
>   	int exp_user;
>   	int exp_err;
>   } tcases[] = {
> -	{&queue_id,&rcv_buf, 4, 1, 0, 0, E2BIG},
> -	{&queue_id,&rcv_buf, MSGSIZE, 1, 0, 1, EACCES},
> -	{&queue_id, NULL, MSGSIZE, 1, 0, 0, EFAULT},
> -	{&bad_id,&rcv_buf, MSGSIZE, 1, 0, 0, EINVAL},
> -	{&queue_id,&rcv_buf, -1, 1, 0, 0, EINVAL},
> -	{&queue_id,&rcv_buf, MSGSIZE, 2, IPC_NOWAIT, 0, ENOMSG},
> +	{&queue_id,&rcv_buf, MSGSIZE - 1, 2, 0, 0, E2BIG},
> +	{&queue_id,&rcv_buf, MSGSIZE,     2, 0, 1, EACCES},
> +	{&queue_id, NULL,     MSGSIZE,     2, 0, 0, EFAULT},
> +	{&bad_id,&rcv_buf, MSGSIZE,     2, 0, 0, EINVAL},
> +	{&queue_id,&rcv_buf, -1,          2, 0, 0, EINVAL},
> +
> +	{&queue_id,&rcv_buf, MSGSIZE,  3, IPC_NOWAIT,              0, ENOMSG},
> +	{&queue_id,&rcv_buf, MSGSIZE, -1, IPC_NOWAIT,              0, ENOMSG},
> +	{&queue_id,&rcv_buf, MSGSIZE, -1, IPC_NOWAIT | MSG_EXCEPT, 0, ENOMSG},
>   };
>
>   static void verify_msgrcv(struct tcase *tc)
Cyril Hrubis Oct. 13, 2021, 10:06 a.m. UTC | #2
Hi!
> Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  .../kernel/syscalls/ipc/msgrcv/msgrcv02.c     | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> index cfb7d7446..fba6a5289 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> @@ -21,6 +21,8 @@
>   *   msgflg and no message of the requested type existed on the message queue.
>   */
>  
> +#define _GNU_SOURCE
> +
>  #include <string.h>
>  #include <sys/wait.h>
>  #include <sys/msg.h>
> @@ -38,7 +40,7 @@ struct passwd *pw;
>  static struct buf {
>  	long type;
>  	char mtext[MSGSIZE];
> -} rcv_buf, snd_buf = {MSGTYPE, "hello"};
> +} rcv_buf, snd_buf = {2, "hello"};
>  
>  static struct tcase {
>  	int *id;
> @@ -49,12 +51,15 @@ static struct tcase {
>  	int exp_user;
>  	int exp_err;
>  } tcases[] = {
> -	{&queue_id, &rcv_buf, 4, 1, 0, 0, E2BIG},
> -	{&queue_id, &rcv_buf, MSGSIZE, 1, 0, 1, EACCES},
> -	{&queue_id, NULL, MSGSIZE, 1, 0, 0, EFAULT},
> -	{&bad_id, &rcv_buf, MSGSIZE, 1, 0, 0, EINVAL},
> -	{&queue_id, &rcv_buf, -1, 1, 0, 0, EINVAL},
> -	{&queue_id, &rcv_buf, MSGSIZE, 2, IPC_NOWAIT, 0, ENOMSG},
> +	{&queue_id, &rcv_buf, MSGSIZE - 1, 2, 0, 0, E2BIG},
> +	{&queue_id, &rcv_buf, MSGSIZE,     2, 0, 1, EACCES},
> +	{&queue_id, NULL,     MSGSIZE,     2, 0, 0, EFAULT},
> +	{&bad_id,   &rcv_buf, MSGSIZE,     2, 0, 0, EINVAL},
> +	{&queue_id, &rcv_buf, -1,          2, 0, 0, EINVAL},
> +

I wouldn't have added this empty line. The rest of the spaces that
aligns the fields looks good to me though, it's easier to read that way.

> +	{&queue_id, &rcv_buf, MSGSIZE,  3, IPC_NOWAIT,              0, ENOMSG},
> +	{&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT,              0, ENOMSG},
> +	{&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT | MSG_EXCEPT, 0, ENOMSG},
>  };

With the empty line removed:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Richard Palethorpe Oct. 13, 2021, 11:32 a.m. UTC | #3
Hello,

Thanks, pushed with line removed!
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
index cfb7d7446..fba6a5289 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
@@ -21,6 +21,8 @@ 
  *   msgflg and no message of the requested type existed on the message queue.
  */
 
+#define _GNU_SOURCE
+
 #include <string.h>
 #include <sys/wait.h>
 #include <sys/msg.h>
@@ -38,7 +40,7 @@  struct passwd *pw;
 static struct buf {
 	long type;
 	char mtext[MSGSIZE];
-} rcv_buf, snd_buf = {MSGTYPE, "hello"};
+} rcv_buf, snd_buf = {2, "hello"};
 
 static struct tcase {
 	int *id;
@@ -49,12 +51,15 @@  static struct tcase {
 	int exp_user;
 	int exp_err;
 } tcases[] = {
-	{&queue_id, &rcv_buf, 4, 1, 0, 0, E2BIG},
-	{&queue_id, &rcv_buf, MSGSIZE, 1, 0, 1, EACCES},
-	{&queue_id, NULL, MSGSIZE, 1, 0, 0, EFAULT},
-	{&bad_id, &rcv_buf, MSGSIZE, 1, 0, 0, EINVAL},
-	{&queue_id, &rcv_buf, -1, 1, 0, 0, EINVAL},
-	{&queue_id, &rcv_buf, MSGSIZE, 2, IPC_NOWAIT, 0, ENOMSG},
+	{&queue_id, &rcv_buf, MSGSIZE - 1, 2, 0, 0, E2BIG},
+	{&queue_id, &rcv_buf, MSGSIZE,     2, 0, 1, EACCES},
+	{&queue_id, NULL,     MSGSIZE,     2, 0, 0, EFAULT},
+	{&bad_id,   &rcv_buf, MSGSIZE,     2, 0, 0, EINVAL},
+	{&queue_id, &rcv_buf, -1,          2, 0, 0, EINVAL},
+
+	{&queue_id, &rcv_buf, MSGSIZE,  3, IPC_NOWAIT,              0, ENOMSG},
+	{&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT,              0, ENOMSG},
+	{&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT | MSG_EXCEPT, 0, ENOMSG},
 };
 
 static void verify_msgrcv(struct tcase *tc)