Skip to content

Commit

Permalink
Fix off-by-one error in pidns05
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Richard Palethorpe <[email protected]>
Reported-by: Martin Doucha <[email protected]>
Reported-by: Petr Cervinka <[email protected]>
Reported-by: Wei Gao <[email protected]>
  • Loading branch information
acerv authored and Richard Palethorpe committed Nov 15, 2023
1 parent 5221f31 commit d104d65
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions testcases/kernel/containers/pidns/pidns05.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit d104d65

Please sign in to comment.