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
This commit is contained in:
marcus 2008-12-19 06:50:15 +00:00
parent 2368f18ac4
commit 0abe5b951a
2 changed files with 4 additions and 0 deletions

View File

@ -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];

View File

@ -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);