From 0abe5b951a7aaf746e27a5f530787ec38ea88fac Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 19 Dec 2008 06:50:15 +0000 Subject: [PATCH] Do not segfault when procstat -f or procstat -v is called on a process not owned by the current user. If kinfo_getfile() or kinfo_getvmmap() return NULL, simply exit, and do not try and derefernce the memory. Reviewed by: peter Approved by: peter --- usr.bin/procstat/procstat_files.c | 2 ++ usr.bin/procstat/procstat_vm.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/usr.bin/procstat/procstat_files.c b/usr.bin/procstat/procstat_files.c index 1f620f3fb108..74ec590d50e4 100644 --- a/usr.bin/procstat/procstat_files.c +++ b/usr.bin/procstat/procstat_files.c @@ -144,6 +144,8 @@ procstat_files(pid_t pid, struct kinfo_proc *kipp) "PRO", "NAME"); freep = kinfo_getfile(pid, &cnt); + if (freep == NULL) + return; for (i = 0; i < cnt; i++) { kif = &freep[i]; diff --git a/usr.bin/procstat/procstat_vm.c b/usr.bin/procstat/procstat_vm.c index 79c0e57aa5e7..1873c4f25e6c 100644 --- a/usr.bin/procstat/procstat_vm.c +++ b/usr.bin/procstat/procstat_vm.c @@ -54,6 +54,8 @@ procstat_vm(pid_t pid, struct kinfo_proc *kipp __unused) "PRES", "REF", "SHD", "FL", "TP", "PATH"); freep = kinfo_getvmmap(pid, &cnt); + if (freep == NULL) + return; for (i = 0; i < cnt; i++) { kve = &freep[i]; printf("%5d ", pid);