]> granicus.if.org Git - procps-ng/commitdiff
top: fix potential SEGV when no tasks were displayable
authorJim Warner <james.warner@comcast.net>
Wed, 9 Sep 2020 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Sun, 13 Sep 2020 00:00:49 +0000 (10:00 +1000)
This patch fixes a nearly decade old bug discovered by
Frederik Deweerdt. His merge request shown below would
be an adequate solution except for iterative overhead.

This alternate patch will represent substantially less
overhead for an admittedly extremely rare possibility.

Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/114

And-thanks-to: Frederik Deweerdt <fdeweerdt@fastly.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
NEWS
top/top.c

diff --git a/NEWS b/NEWS
index eacc1d5e81e9cf7e4b52df1a1ea59ac6e7beb341..d616162c77b062f6620322073c111ebb731bbf3e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ procps-ng NEXT
   * top: add command line 'e' for symmetry with 'E'        issue #165
   * top: add '4' toggle for two abreast cpu display        issue #172
   * top: add '!' toggle for combining multiple cpus
+  * top: fix potential SEGV involving -p switch            merge #114
   * vmstat: Wide mode gives wider proc columns             merge #48
   * watch: Add environment variable for interval           merge #62
 
index fb06c2adc977302d8d4ff4127e72c01238f6853a..7732adfd44e575e1720e3a2f8c576973fd77186b 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -6045,6 +6045,8 @@ static int window_show (WIN_t *q, int wmax) {
 
    // Display Column Headings -- and distract 'em while we sort (maybe)
    PUFF("\n%s%s%s", q->capclr_hdr, q->columnhdr, Caps_endline);
+   // and just in case 'Monpids' is active but matched no processes ...
+   if (!PIDSmaxt) return 1;                         // 1 for the column header
 
    if (CHKw(q, Show_FOREST))
       forest_begin(q);