#1010071 wireguard-tools: the wg tool outputs color on monochrome terminals

Package:
wireguard-tools
Source:
wireguard
Description:
fast, modern, secure kernel VPN tunnel (userland utilities)
Submitter:
Axel
Date:
2022-04-24 12:42:03 UTC
Severity:
normal
#1010071#5
Date:
2022-04-23 17:15:06 UTC
From:
To:
Dear Maintainer,

The wg tool outputs color on monochrome terminals, it should either default
to no color output or use a proper terminal library like ncurses to output
color instead of just querying if the terminal is a tty.

I really don't like having to set a different environment variable to
disable color output for each program which behaves like this.

Kind regards,
Axel

#1010071#10
Date:
2022-04-24 12:02:34 UTC
From:
To:
Hi,

Complaining doesn't help. I've created the following patch which fixes
the issue.
--- terminal.c.orig 2022-04-24 13:57:34.231668500 +0200 +++ terminal.c 2022-04-24 13:57:38.519643229 +0200 @@ -24,8 +24,11 @@ mode = true; else if (var && !strcmp(var, "never")) mode = false; - else - mode = isatty(fileno(stdout)); + else { + var = getenv("TERM"); + mode = var && isatty(fileno(stdout)) && + strcmp(var + strlen(var) - 5, "color") == 0; + } return mode; } It's also attached as a patch file. Kind regards, Axel
#1010071#15
Date:
2022-04-24 12:38:48 UTC
From:
To:
Hi again,

This patch avoids out of bounds access.
--- terminal.c.orig 2022-04-24 13:57:34.231668500 +0200 +++ terminal.c 2022-04-24 14:34:35.798847083 +0200 @@ -24,8 +24,10 @@ mode = true; else if (var && !strcmp(var, "never")) mode = false; - else - mode = isatty(fileno(stdout)); + else { + var = getenv("TERM"); + mode = var && isatty(fileno(stdout)) && strstr(var, "color"); + } return mode; } Kind regards, Axel