From patchwork Fri Oct 13 13:57:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 825482 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XQ/hgQm4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yD8Rl2Snyz9sNr for ; Sat, 14 Oct 2017 00:57:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758140AbdJMN5h (ORCPT ); Fri, 13 Oct 2017 09:57:37 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34926 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753374AbdJMN5g (ORCPT ); Fri, 13 Oct 2017 09:57:36 -0400 Received: by mail-wr0-f193.google.com with SMTP id y44so988255wry.2 for ; Fri, 13 Oct 2017 06:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gOP81V2SLb1xbrzuhuLH4CE79pSfwQA5dRD++xkoMYQ=; b=XQ/hgQm4i6cPRE2XZuo2107nfTDc5TwGYjTZQwXiylfJ3mCafTTBocYcR8tmwODmMl ws6e3TN6bbRdt/ytMkgh3ciH3u2VmME13pMaD30Ncnwkf52tcrkwDByllGs0KmieHFha EhrUrEBJOIoV0mNyHhSw8RYMX8DqQeU1T3jkuKJklti1v2gl+D2PMax//WqKwjciBQf3 thVFrxztXvFZnE8uJmsQYCaU61yuK1Tg3cotbDiuQOq6MnpoYRQdMgh1K3pykig85Vnx zNebUYEu3CujU6i+zt1GjuBdO7BM/CVOdRloFk8uCbn2lKDVe7CmnzQssOKw/nuVAw61 LY0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gOP81V2SLb1xbrzuhuLH4CE79pSfwQA5dRD++xkoMYQ=; b=URv5W8PrT1ztkIJlV0e+bOI5pa1iSrboJ5Chcvcs9TLTdOBv+Z0/ai+N8euLGGhyU2 XSork0+d7xKahge5TAGN+LtP82Cw1QNm/YmBiMRob+d43i4bYj9rpMSzUzVdByeOfFdx dnKj0DTzyRO3IOveOic9Swm2N9y6wfp2+RCDTyx5MsC8XxYSSD3cpOUr8H7XTJmhy+Dj dIkFnYffx/ElBFfoVI9hZ81g/m1Q+PRvIhs/VxJoSnOIQdLSSK+1rIMx+MeBSPB8MpXk 15Rdp3UVUTVDh+tW2wtiRmhJlyo8AnGN0jL5GcPlmXCeCjVgijVp67RakgYANmF+rHRI 9vFA== X-Gm-Message-State: AMCzsaUoQE8cmNRxNSGyeS/DCEM+6xeI3mAXo/kNn2cIHVr+LACZ6Vvg WW0BUQCDtH4Ne0wGSp6W9nUeNg== X-Google-Smtp-Source: AOwi7QCwqTo8TwVVg+9unfFSKyKlPPB8BmxT3Th4hJbdW+zi3dHRH60Cjd1STQ/XkDxhhYzs35XbBg== X-Received: by 10.223.158.74 with SMTP id v10mr1617087wre.201.1507903054911; Fri, 13 Oct 2017 06:57:34 -0700 (PDT) Received: from localhost.localdomain ([85.119.94.113]) by smtp.gmail.com with ESMTPSA id q16sm1414348wrg.96.2017.10.13.06.57.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 06:57:34 -0700 (PDT) From: Petr Vorel To: netdev@vger.kernel.org Cc: Petr Vorel , Julien Fortin , Stephen Hemminger Subject: [PATCH iproute2 v2 1/4] color: Fix ip segfault when using --color switch Date: Fri, 13 Oct 2017 15:57:16 +0200 Message-Id: <20171013135719.18450-2-petr.vorel@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171013135719.18450-1-petr.vorel@gmail.com> References: <20171013135719.18450-1-petr.vorel@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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);