]> granicus.if.org Git - procps-ng/commitdiff
top: other graph_cpus, graph_mems, and summ_mscale fix
authorJim Warner <james.warner@comcast.net>
Fri, 18 May 2018 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sat, 19 May 2018 11:22:56 +0000 (21:22 +1000)
This patch replaces an original patch referenced below
which has now been reversed. We now validate variables
'graph_cpus', 'graph_mems' and 'summ_mscale' just once
at startup. Thereafter, top enforces the proper range.

[ we afford the same treatment to that 'task_mscale' ]
[ variable, which was ignored in the original patch. ]

Reference(s):
. original qualys patch
0099-top-Check-graph_cpus-graph_mems-and-summ_mscale.patch
commit cd8ba5670e21f8016e14efd247ed2dd6af887aea

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 5244e5891937a33b9c3c37d7e022bb437f399159..e9d750c05181491d48ceaf34087018a93f12cb7b 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -3756,6 +3756,11 @@ error Hey, fix the above fscanf 'PFLAGSSIZ' dependency !
             return p;
       if (UNSAFE_SORTINDX(w->rc.sortindx, sizeof(Fieldstab) / sizeof(Fieldstab[0])))
          return p;
+      if (w->rc.graph_cpus < 0 || w->rc.graph_cpus > 2)
+         return p;
+      if (w->rc.graph_mems < 0 || w->rc.graph_mems > 2)
+         return p;
+
       if (4 != fscanf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
          , &w->rc.summclr, &w->rc.msgsclr
          , &w->rc.headclr, &w->rc.taskclr))
@@ -3795,6 +3800,10 @@ error Hey, fix the above fscanf 'PFLAGSSIZ' dependency !
          ;                                  // avoid -Wunused-result
    if (Rc.fixed_widest < -1 || Rc.fixed_widest > SCREENMAX)
       Rc.fixed_widest = 0;
+   if (Rc.summ_mscale < 0   || Rc.summ_mscale > SK_Eb)
+      Rc.summ_mscale = 0;
+   if (Rc.task_mscale < 0   || Rc.task_mscale > SK_Pb)
+      Rc.task_mscale = 0;
 
    // we'll start off Inspect stuff with 1 'potential' blank line
    // ( only realized if we end up with Inspect.total > 0 )
@@ -5619,7 +5628,7 @@ numa_nope:
       }
 
       if (w->rc.graph_mems) {
-         static struct {
+         static const struct {
             const char *used, *misc, *swap, *type;
          } gtab[] = {
             { "%-.*s~7", "%-.*s~8", "%-.*s~8", Graph_bars },