From: kettenis Date: Wed, 19 May 2021 18:10:45 +0000 (+0000) Subject: In ttyinfo() check that ps_vmspace isn't NULL before calculating the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2c417a9eed782cc86302610b11dd2650081be304;p=openbsd In ttyinfo() check that ps_vmspace isn't NULL before calculating the resident set size. This replicates what the sysctl code does and fixes a kernel crash reported by robert@ ok deraadt@ --- diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 169c3d1cdf7..7f41b2bf923 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.168 2021/05/16 15:10:20 deraadt Exp $ */ +/* $OpenBSD: tty.c,v 1.169 2021/05/19 18:10:45 kettenis Exp $ */ /* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */ /*- @@ -2157,7 +2157,7 @@ empty: ttyprintf(tp, "empty foreground process group\n"); fixpt_t pctcpu, pctcpu2; int run, run2; int calc_pctcpu; - long rss; + long rss = 0; /* * Pick the most active process: @@ -2194,8 +2194,9 @@ update_pickpr: /* Calculate percentage cpu, resident set size. */ calc_pctcpu = (pctcpu * 10000 + FSCALE / 2) >> FSHIFT; - rss = (pickpr->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) ? 0 : - vm_resident_count(pickpr->ps_vmspace); + if ((pickpr->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) == 0 && + pickpr->ps_vmspace != NULL) + rss = vm_resident_count(pickpr->ps_vmspace); calctsru(&pickpr->ps_tu, &utime, &stime, NULL);