[LTP] [PATCH v1] Fix off-by-one error in pidns05

Richard Palethorpe rpalethorpe@suse.de
Wed Nov 15 14:14:47 CET 2023


Hello,

Merged, thanks!

Andrea Cervesato <andrea.cervesato@suse.de> writes:

> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> Since we count nested processes from zero, we need to check that nested
> level value is not bigger than MAX_DEPTH - 1. This patch also remove
> shared pointer which counts number of levels and replace it with a
> regular scalar value.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  testcases/kernel/containers/pidns/pidns05.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/containers/pidns/pidns05.c b/testcases/kernel/containers/pidns/pidns05.c
> index 0e7739aaa..7843fe7a9 100644
> --- a/testcases/kernel/containers/pidns/pidns05.c
> +++ b/testcases/kernel/containers/pidns/pidns05.c
> @@ -24,7 +24,7 @@ static struct tst_clone_args clone_args = {
>  };
>  static pid_t pid_max;
>  
> -static void child_func(int *level)
> +static void child_func(const int level)
>  {
>  	pid_t cpid, ppid;
>  
> @@ -34,15 +34,13 @@ static void child_func(int *level)
>  	TST_EXP_EQ_LI(cpid, 1);
>  	TST_EXP_EQ_LI(ppid, 0);
>  
> -	if (*level >= MAX_DEPTH) {
> +	if (level >= MAX_DEPTH - 1) {
>  		TST_CHECKPOINT_WAKE(0);
>  		return;
>  	}
>  
> -	(*level)++;
> -
>  	if (!SAFE_CLONE(&clone_args)) {
> -		child_func(level);
> +		child_func(level + 1);
>  		return;
>  	}
>  
> @@ -81,14 +79,13 @@ static void setup(void)
>  static void run(void)
>  {
>  	int i, status, children;
> -	int level = 0;
>  	pid_t pids_new[MAX_DEPTH];
>  	pid_t pids[MAX_DEPTH];
>  	pid_t pid;
>  
>  	pid = SAFE_CLONE(&clone_args);
>  	if (!pid) {
> -		child_func(&level);
> +		child_func(0);
>  		return;
>  	}
>  
> -- 
> 2.35.3


-- 
Thank you,
Richard.


More information about the ltp mailing list