From: Petr Vorel <petr.vorel@gmail.com>
To: netdev@vger.kernel.org
Cc: Petr Vorel <petr.vorel@gmail.com>,
Julien Fortin <julien@cumulusnetworks.com>,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2 v2 2/4] color: Fix another ip segfault when using --color switch
Date: Fri, 13 Oct 2017 15:57:17 +0200 [thread overview]
Message-ID: <20171013135719.18450-3-petr.vorel@gmail.com> (raw)
In-Reply-To: <20171013135719.18450-1-petr.vorel@gmail.com>
Commit 959f1428 ("color: add new COLOR_NONE and disable_color function")
introducing color enum COLOR_NONE, which is not only duplicite of
COLOR_CLEAR, but also caused segfault, when running ip with --color
switch, as 'attr + 8' in color_fprintf() access array item out of
bounds. Thus removing it and restoring "magic" offset + 7.
Reproduce with:
$ ip -c a
Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
include/color.h | 1 -
lib/color.c | 4 ++--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/include/color.h b/include/color.h
index 1cd6f7d2..c183ef79 100644
--- a/include/color.h
+++ b/include/color.h
@@ -2,7 +2,6 @@
#define __COLOR_H__ 1
enum color_attr {
- COLOR_NONE,
COLOR_IFNAME,
COLOR_MAC,
COLOR_INET,
diff --git a/lib/color.c b/lib/color.c
index 79d5e289..05afcb21 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -104,13 +104,13 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
va_start(args, fmt);
- if (!color_is_enabled || attr == COLOR_NONE) {
+ if (!color_is_enabled || attr == COLOR_CLEAR) {
ret = vfprintf(fp, fmt, args);
goto end;
}
ret += fprintf(fp, "%s",
- color_codes[attr_colors[is_dark_bg ? attr + 8 : attr]]);
+ color_codes[attr_colors[is_dark_bg ? attr + 7 : attr]]);
ret += vfprintf(fp, fmt, args);
ret += fprintf(fp, "%s", color_codes[C_CLEAR]);
--
2.14.2
next prev parent reply other threads:[~2017-10-13 13:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-13 13:57 [PATCH iproute2 v2 0/4] Fix ip segfault when using --color switch Petr Vorel
2017-10-13 13:57 ` [PATCH iproute2 v2 1/4] color: " Petr Vorel
2017-10-13 13:57 ` Petr Vorel [this message]
2017-10-13 13:57 ` [PATCH iproute2 v2 3/4] color: Cleanup code to remove "magic" offset + 7 Petr Vorel
2017-10-13 13:57 ` [PATCH iproute2 v2 4/4] color: Rename enum Petr Vorel
2017-10-16 16:24 ` [PATCH iproute2 v2 0/4] Fix ip segfault when using --color switch Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171013135719.18450-3-petr.vorel@gmail.com \
--to=petr.vorel@gmail.com \
--cc=julien@cumulusnetworks.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).