From patchwork Mon May 12 04:49:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 2084472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zx2Yq0VkJz1yZ0 for ; Tue, 13 May 2025 00:49:18 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1uEUTB-00071v-9R; Mon, 12 May 2025 14:49:29 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1uEUT9-00070o-SA for fwts-devel@lists.ubuntu.com; Mon, 12 May 2025 14:49:27 +0000 Received: from canonical.com (unknown [213.157.19.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 85C393F190 for ; Mon, 12 May 2025 14:49:27 +0000 (UTC) From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_log: fix the potential overflow for dumping all log fields Date: Mon, 12 May 2025 22:49:20 +0800 Message-Id: <20250512144921.27555-5-ivan.hu@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512144921.27555-1-ivan.hu@canonical.com> References: <20250512144921.27555-1-ivan.hu@canonical.com> MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Buglink: https://bugs.launchpad.net/fwts/+bug/2110180 Got coverity scan warning, CID 520641: (#1 of 1): Overflowed constant (INTEGER_OVERFLOW) overflow_const: Expression field, overflows the type of field, which is type fwts_log_field. Simply add the for loop range for get rid of coverity scan warning. Signed-off-by: Ivan Hu --- src/lib/src/fwts_log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c index 48240201..2cac0b04 100644 --- a/src/lib/src/fwts_log.c +++ b/src/lib/src/fwts_log.c @@ -204,7 +204,7 @@ void fwts_log_print_fields(void) fwts_log_field field; printf("Available fields: "); - for (field = 1; ; field <<= 1) { + for (field = 1; field <= LOG_NO_FIELDS; field <<= 1) { char *str = fwts_log_field_to_str(field); if (strcmp(str, LOG_UNKNOWN_FIELD) == 0) break;