]> granicus.if.org Git - procps-ng/commitdiff
top: provide the means to exploit a 256-color terminal
authorJim Warner <james.warner@comcast.net>
Tue, 5 Jun 2018 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sat, 9 Jun 2018 11:35:20 +0000 (21:35 +1000)
With the Qualys security audit, we began to harden our
treatment of the top rcfile. In particular, the values
read were checked so as to prevent some malicious user
from editing it in order to achieve an evil objective.

However when it came to colors I was surprised to find
that at least one user edited the rcfile for 256-color
support. Unfortunately, our new checks prevented this.

So this commit will provide the means to exploit those
extra colors with no need to manually edit the rcfile.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/96

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

index a83665ece4a7e95ed12cf7b9100e177c539b19ad..0671e301ba3f18d0c53c9962c8be0e763405831a 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -3293,10 +3293,11 @@ static const char *config_file (FILE *fp, const char *name, float *delay) {
       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))
             return p;
-      if (w->rc.summclr < 0 || w->rc.summclr > 7) return p;
-      if (w->rc.msgsclr < 0 || w->rc.msgsclr > 7) return p;
-      if (w->rc.headclr < 0 || w->rc.headclr > 7) return p;
-      if (w->rc.taskclr < 0 || w->rc.taskclr > 7) return p;
+      // would prefer to use 'max_colors', but it isn't available yet...
+      if (w->rc.summclr < 0 || w->rc.summclr > 255) return p;
+      if (w->rc.msgsclr < 0 || w->rc.msgsclr > 255) return p;
+      if (w->rc.headclr < 0 || w->rc.headclr > 255) return p;
+      if (w->rc.taskclr < 0 || w->rc.taskclr > 255) return p;
 
       switch (Rc.id) {
          case 'a':                          // 3.2.8 (former procps)
@@ -3880,7 +3881,7 @@ signify_that:
       putp(Cap_home);
       // this string is well above ISO C89's minimum requirements!
       show_special(1, fmtmk(N_unq(COLOR_custom_fmt)
-         , PACKAGE_STRING, w->grpname
+         , w->grpname
          , CHKw(w, View_NOBOLD) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
          , CHKw(w, Show_COLORS) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
          , CHKw(w, Show_HIBOLD) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
@@ -3918,6 +3919,16 @@ signify_that:
             clr = key - '0';
             *pclr = clr;
             break;
+         case kbd_UP:
+            ++clr;
+            if (clr >= max_colors) clr = 0;
+            *pclr = clr;
+            break;
+         case kbd_DOWN:
+            --clr;
+            if (clr < 0) clr = max_colors - 1;
+            *pclr = clr;
+            break;
          case 'B':
             TOGw(w, View_NOBOLD);
             break;
index 08008ffb38b1877133c08a356a2121fb75d6d5fe..ab27972046370ea02f2da859475d20918ef01d95 100644 (file)
@@ -609,36 +609,11 @@ static void build_uniq_nlstab (void) {
    .  this form and any translation could produce unpleasing results
    .  that are unlikely to parallel the running top program.
    .
-   .  If you decide to proceed with translation, do the following
-   .  lines only, taking care not to disturbe the tilde + number.
-   .
-   .  Simulated screen excerpt:
-   .     --> "   Tasks:~3  64 ~2total,~3   2 ~3running,~3  62
-   .     --> "   %%Cpu(s):~3  76.5 ~2user,~3  11.2 ~2system,~
-   .     --> "   ~1 Nasty Message! ~4  -or-  ~1Input Prompt~5
-   .
-   .  Other translatable text
-   .     --> "   available toggles: ~1B~2 =disable bold globa
-   .     --> "       ~1z~2 =color/mono (~1%s~2), ~1b~2 =tasks
-   .
-   .     --> "1) Select ~1target~2 as upper case letter:\n"
-   .     --> "   S~2 = Summary Data,~1  M~2 = Messages/Prompt
-   .     --> "   H~2 = Column Heads,~1  T~2 = Task Informatio
-   .     --> "2) Select ~1color~2 as number:\n"
-   .     --> "   0~2 = black,~1  1~2 = red,    ~1  2~2 = gree
-   .     --> "   4~2 = blue, ~1  5~2 = magenta,~1  6~2 = cyan
-   . *   --> "\n"
-   .     --> "3) Then use these keys when finished:\n"
-   .     --> "   'q' to abort changes to window '~1%s~2'\n"
-   . **  --> "   'a' or 'w' to commit & change another, <Ente
-   .
-   .     Note:
-   . *      maybe sacrifice the entire line (with the "\n") ...
-   . **     ... so <Enter> text potion could be on its own line
+   .  If you decide to proceed with translation, please take care
+   .  to not disturb the spaces and the tilde + number delimiters.
    . */
    Uniq_nlstab[COLOR_custom_fmt] = _(""
-      "Help for color mapping~2 - %s\n"
-      "current window: ~1%s~6\n"
+      "Help for color mapping~2 - \"Current Window\" = ~1 %s ~6\n"
       "\n"
       "   color - 04:25:44 up 8 days, 50 min,  7 users,  load average:\n"
       "   Tasks:~3  64 ~2total,~3   2 ~3running,~3  62 ~2sleeping,~3   0 ~2stopped,~3\n"
@@ -654,7 +629,8 @@ static void build_uniq_nlstab (void) {
       "1) Select a ~1target~2 as an upper case letter, ~1current target~2 is ~1 %c ~4:\n"
       "   S~2 = Summary Data,~1  M~2 = Messages/Prompts,\n"
       "   H~2 = Column Heads,~1  T~2 = Task Information\n"
-      "2) Select a ~1color~2 as a number, ~1current color~2 is ~1 %d ~4:\n"
+      "2) Select a ~1color~2 as a number or use the up/down arrow keys\n"
+      "   to raise/lower the 256 colors value, ~1current color~2 is ~1 %d ~4:\n"
       "   0~2 = black,~1  1~2 = red,    ~1  2~2 = green,~1  3~2 = yellow,\n"
       "   4~2 = blue, ~1  5~2 = magenta,~1  6~2 = cyan, ~1  7~2 = white\n"
       "\n"