Skip to content

Commit

Permalink
ps: fix segfault with pids=NULL
Browse files Browse the repository at this point in the history
When pids is NULL, we should not try to access it.

Closes: #1239

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Jul 4, 2023
1 parent d5e50d3 commit 19cd8aa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ crun_command_ps (struct crun_global_arguments *global_args, int argc, char **arg
{
case PS_JSON:
printf ("[\n");
for (i = 0; pids[i]; i++)
for (i = 0; pids && pids[i]; i++)
printf (" %d%s\n", pids[i], pids[i + 1] ? "," : "");
printf ("]\n");
break;

case PS_TABLE:
printf ("PID\n");
for (i = 0; pids[i]; i++)
for (i = 0; pids && pids[i]; i++)
printf ("%d\n", pids[i]);
break;
}
Expand Down

0 comments on commit 19cd8aa

Please sign in to comment.