netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 1/4] color: Fix ip segfault when using --color switch
Date: Fri, 13 Oct 2017 15:57:16 +0200	[thread overview]
Message-ID: <20171013135719.18450-2-petr.vorel@gmail.com> (raw)
In-Reply-To: <20171013135719.18450-1-petr.vorel@gmail.com>

Commit d0e72011 ("ip: ipaddress.c: add support for json output")
introduced passing -1 as enum color_attr. This is not only wrong as no
color_attr has value -1, but also causes another segfault in color_fprintf()
on this setup as there is no item with index -1 in array of enum attr_colors[].
Using COLOR_CLEAR is valid option.

Reproduce with:
$ COLORFGBG='0;15' ip -c a

NOTE: COLORFGBG is environmental variable used for defining whether user
has light or dark background.
COLORFGBG="0;15" is used to ask for color set suitable for light background,
COLORFGBG="15;0" is used to ask for color set suitable for dark background.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 include/json_print.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/json_print.h b/include/json_print.h
index b6ce1f9f..596af35a 100644
--- a/include/json_print.h
+++ b/include/json_print.h
@@ -53,7 +53,7 @@ void close_json_array(enum output_type type, const char *delim);
 					     const char *fmt,		\
 					     type value)		\
 	{								\
-		print_color_##type_name(t, -1, key, fmt, value);	\
+		print_color_##type_name(t, COLOR_CLEAR, key, fmt, value);	\
 	}
 _PRINT_FUNC(int, int);
 _PRINT_FUNC(bool, bool);
-- 
2.14.2

  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 ` Petr Vorel [this message]
2017-10-13 13:57 ` [PATCH iproute2 v2 2/4] color: Fix another " Petr Vorel
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-2-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).