From patchwork Tue Jun 12 06:04:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 928114 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=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="kcwiI0g7"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 414ffL0GHwz9rxs for ; Tue, 12 Jun 2018 16:11:37 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id BAADAC21E62; Tue, 12 Jun 2018 06:06:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3B10EC21E4E; Tue, 12 Jun 2018 06:05:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E67DDC21E4E; Tue, 12 Jun 2018 06:05:35 +0000 (UTC) Received: from mail-io0-f171.google.com (mail-io0-f171.google.com [209.85.223.171]) by lists.denx.de (Postfix) with ESMTPS id 46A86C21C8B for ; Tue, 12 Jun 2018 06:05:31 +0000 (UTC) Received: by mail-io0-f171.google.com with SMTP id k3-v6so12665947iog.3 for ; Mon, 11 Jun 2018 23:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2mlsTdsnu+3FmnzBo2b7HIACXNS4j7c5Hv7vAeEI5ng=; b=kcwiI0g7qisWR5ZMN7RhRqQElmSMAMwS9j3EqkoHswy1OGqi8HLfl8Zfj5N8+LML07 fg6CX2fpy8Y8C2+2yeY31e5WcfnGWlO4QdFxV28Lo1tPWaUgUb+P6XOYUkrXuw0sLFZ3 HfCu34VMrbS+pwvMqVOmuUaLSupGJGhSLQvKTCwGeUIrdNVgqhMxlyms5oV4XhXkvvM0 ApijNPyrRS7ZQyNuzz5dPvHrJnwuFnAFppH/ShTt/ptu2qj0LsimSc4Q+zJD0VBD0LZT 3GjD8yQTD6AGgYb3Gr5dNBlvcUZXRD6Rmx638Uws0fCk+ynOIbJl7rsO2mm1Un+3bt8l k/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2mlsTdsnu+3FmnzBo2b7HIACXNS4j7c5Hv7vAeEI5ng=; b=XSJYWAqRtLdM94Z+lBEGisoze6aQ9nPlWBK9nG1RVCzTA8Variqdcx3FQh5pBjd4G9 gI0g6JN3xe3A0L0L7RZSFRXK9/oRKuwHR9R6QRkNGtOzoxQ4+sqgN+TiF+031aWAPNKG 8q+U5AFJFpCfHUpntv/5KtCVSwOt9Wr6qdDyum7ZSk7EEGeeNBose2Rs44yNBCEd5poP tpILNmFJWhE0+x5AmtFRL/PQq8W9FajAIAUmebrYndGX39/LT5Rqp59fL3wxH61OI3Mb Fhs47tOjCA1EUGMW4/bFWlMP51V/KSW6KEogIqPw9+7EkMv1cOOwAqZ2+TLEhRE1XhHm dnPQ== X-Gm-Message-State: APt69E0xFoL4FYJXSYsquVPiBDMyHrNxeXmBc7W9tB0GwhRSAD65CeuW 7Vk1cC169wHkNG31jF/h9cDkZg== X-Google-Smtp-Source: ADUXVKIbdKeMjJMOZwC8Hz4P9FRAB0ClIkV2Fp5zCB9qQ8FEvQCf8mKfsdvcGJsp920uecGwYPKnHQ== X-Received: by 2002:a6b:30c9:: with SMTP id w192-v6mr2187097iow.291.1528783529813; Mon, 11 Jun 2018 23:05:29 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id g191-v6sm171826itg.0.2018.06.11.23.05.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 23:05:27 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 06F8E1403E9; Tue, 12 Jun 2018 00:05:27 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 12 Jun 2018 00:04:55 -0600 Message-Id: <20180612060502.196817-2-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180612060502.196817-1-sjg@chromium.org> References: <20180612060502.196817-1-sjg@chromium.org> Cc: Heinrich Schuchardt , Tom Rini Subject: [U-Boot] [PATCH v2 1/8] log: Fix incorect range check in log_get_cat_name() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This allows access to an element after the end of the array. Fix it. Reported-by: Coverity (CID: 173279) Signed-off-by: Simon Glass --- Changes in v2: - Change log_get_cat_name() to always return a valid string, even if the uclass is not found common/log.c | 10 +++++++--- include/log.h | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/log.c b/common/log.c index 3b5588ebe7..59869cd29d 100644 --- a/common/log.c +++ b/common/log.c @@ -38,12 +38,16 @@ static const char *log_level_name[LOGL_COUNT] = { const char *log_get_cat_name(enum log_category_t cat) { - if (cat > LOGC_COUNT) - return "invalid"; + const char *name; + + if (cat < 0 || cat >= LOGC_COUNT) + return ""; if (cat >= LOGC_NONE) return log_cat_name[cat - LOGC_NONE]; - return uclass_get_name((enum uclass_id)cat); + name = uclass_get_name((enum uclass_id)cat); + + return name ? name : ""; } enum log_category_t log_get_cat_by_name(const char *name) diff --git a/include/log.h b/include/log.h index a3edd25546..3e99d6e62b 100644 --- a/include/log.h +++ b/include/log.h @@ -274,7 +274,8 @@ struct log_filter { * log_get_cat_name() - Get the name of a category * * @cat: Category to look up - * @return category name (which may be a uclass driver name) + * @return category name (which may be a uclass driver name) if found, or + * "" if invalid, or "" if not found */ const char *log_get_cat_name(enum log_category_t cat);