From patchwork Fri Oct 23 11:00:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1386657 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=H16C+Whq; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CHh8Z6bK4z9sSs for ; Fri, 23 Oct 2020 22:00:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B4DD88244A; Fri, 23 Oct 2020 13:00:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="H16C+Whq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CF70282457; Fri, 23 Oct 2020 13:00:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3CAD282442 for ; Fri, 23 Oct 2020 13:00:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1603450806; bh=zc5l365ujOoRWXMoyPUujMB8qNcWQx6yqKA+loSUshA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=H16C+WhqiTiG8G/NY3t0Jq7cs7Lqt3mrgdYFpBEOZ6RssMZEU1eYFHTFxwS+Apffs ellSoCNWn34l5umQ8ncKW3r6uP/QasCO2Rdv1Ao0HRB9MTHJ0/hPB/FlcCkfqZ6JBL wi6WZe6Y9uRtOVbTAED8SjunAHuw1ttzwbYWUL1o= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([178.202.41.107]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M3DJv-1kZUdf1EOD-003gco; Fri, 23 Oct 2020 13:00:06 +0200 From: Heinrich Schuchardt To: Simon Glass Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] log: correct and check array size of log categories Date: Fri, 23 Oct 2020 13:00:01 +0200 Message-Id: <20201023110001.6261-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:in8hQWJA3xYMgU/cQXcmFWqk0jqrEQEClp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n15Qu0s/PIi9GjZc1B2YNJVR1mPdxuXmIfPNuY430/CmDLm 9CLiRuOcH1bhVkPVeDmA== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The log command has led to NULL dereferences if an unknown category name name was used due to missing entries in the list of category names. Add compile time checks for the array sizes of log_cat_name and log_lvl_name to avoid future mishaps. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- common/log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) -- 2.28.0 diff --git a/common/log.c b/common/log.c index b7a6ebe298..9b496b5c40 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *log_cat_name[] = { "none", "arch", "board", @@ -28,7 +28,10 @@ static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { "acpi", }; -static const char *log_level_name[LOGL_COUNT] = { +_Static_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE, + "log_cat_name size"); + +static const char *log_level_name[] = { "EMERG", "ALERT", "CRIT", @@ -41,6 +44,8 @@ static const char *log_level_name[LOGL_COUNT] = { "IO", }; +_Static_assert(ARRAY_SIZE(log_level_name) == LOGL_COUNT, "log_level_name size"); + const char *log_get_cat_name(enum log_category_t cat) { const char *name;