From patchwork Tue Oct 3 08:29:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1842493 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 4S09wm2LRvz20Zh for ; Tue, 3 Oct 2023 19:29:43 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qnama-0006Ej-5P; Tue, 03 Oct 2023 08:29:32 +0000 Received: from smtp-relay-canonical-1.internal ([10.131.114.174] helo=smtp-relay-canonical-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qnamW-0006EY-Qx for fwts-devel@lists.ubuntu.com; Tue, 03 Oct 2023 08:29:28 +0000 Received: from canonical.com (118-163-61-247.hinet-ip.hinet.net [118.163.61.247]) (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-1.canonical.com (Postfix) with ESMTPSA id 49FB23F6B9 for ; Tue, 3 Oct 2023 08:29:26 +0000 (UTC) From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_acpi_table: fix fwts_acpi_reserved_zero_array with the input string Date: Tue, 3 Oct 2023 16:29:23 +0800 Message-Id: <20231003082923.259267-1-ivan.hu@canonical.com> X-Mailer: git-send-email 2.34.1 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/2038278 Got below defects for Coverity Scan whec MPAM test calling fwts_acpi_reserved_zero_array, CID 1521581: (STRING_NULL) Calling "fwts_acpi_reserved_zero_array" with the input string ""MPAM"", which is greater than or equal to 4 in length, or not null-terminated. Fix it without function changed. Signed-off-by: Ivan Hu --- src/lib/src/fwts_acpi_tables.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c index 377b9676..fbab323f 100644 --- a/src/lib/src/fwts_acpi_tables.c +++ b/src/lib/src/fwts_acpi_tables.c @@ -1485,8 +1485,8 @@ void fwts_acpi_reserved_zero_array( char label[20]; uint8_t i; - strncpy(label + 4, "ReservedNonZero", sizeof(label) - 4); - strncpy(label, table, 4); /* ACPI table name is 4 char long */ + strncpy(label, table, sizeof(label) - 1); + strcat(label, "ReservedNonZero"); for (i = 0; i < length; i++) value += data[i];