From dd2b23006caa2323a12749dfc0d831a26a79bc5b Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Mon, 9 Jan 2023 08:40:20 -0800 Subject: [PATCH] fuser: fix loop over kinfo_proc array The previous code would skip as many entries at the end of the array as there were zombies in the list. While here fix type of cnt. Submitted by: Ali Abdallah PR: 232702 MFC After: 2 weeks --- usr.bin/fstat/fuser.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/usr.bin/fstat/fuser.c b/usr.bin/fstat/fuser.c index ad4aebf4a2c..2d9aa72875f 100644 --- a/usr.bin/fstat/fuser.c +++ b/usr.bin/fstat/fuser.c @@ -163,12 +163,12 @@ int do_fuser(int argc, char *argv[]) { struct consumer *consumer; - struct kinfo_proc *p, *procs; + struct kinfo_proc *procs; struct procstat *procstat; struct reqfile *reqfiles; char *ep, *nlistf, *memf; - int ch, cnt, sig; - unsigned int i, nfiles; + int ch, sig; + unsigned int i, cnt, nfiles; sig = SIGKILL; /* Default to kill. */ nlistf = NULL; @@ -253,10 +253,9 @@ do_fuser(int argc, char *argv[]) /* * Walk through process table and look for matching files. */ - p = procs; - while(cnt--) - if (p->ki_stat != SZOMB) - dofiles(procstat, p++, reqfiles, nfiles); + for (i = 0; i < cnt; i++) + if (procs[i].ki_stat != SZOMB) + dofiles(procstat, &procs[i], reqfiles, nfiles); for (i = 0; i < nfiles; i++) { fprintf(stderr, "%s:", reqfiles[i].name);