top: provide the means to exploit a 256-color terminal

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>
This commit is contained in:
Jim Warner 2018-06-04 00:00:00 -05:00 committed by Craig Small
parent 3352bddba5
commit cf057d2fe5
3 changed files with 22 additions and 34 deletions

1
NEWS
View File

@ -1,6 +1,7 @@
procps-ng-NEXT
----------------
* docs: Use correct symbols for -h option in free.1 Debian #898774
* top: can now exploit 256-color terminals issue #96
procps-ng-3.3.15
----------------

View File

@ -3761,10 +3761,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)
@ -4348,7 +4349,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)
@ -4386,6 +4387,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;

View File

@ -606,36 +606,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"
@ -651,7 +626,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"