From patchwork Mon Nov 4 11:52:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 1188892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 476B4Z71Bqz9s7T; Mon, 4 Nov 2019 22:52:45 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iRauW-0003Ei-V9; Mon, 04 Nov 2019 11:52:40 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iRauW-0003Ec-5Z for fwts-devel@lists.ubuntu.com; Mon, 04 Nov 2019 11:52:40 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iRauV-0007f0-W1; Mon, 04 Nov 2019 11:52:40 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_framework: use strlcpy instead of strncpy, fixes gcc-10 build errors Date: Mon, 4 Nov 2019 11:52:39 +0000 Message-Id: <20191104115239.137035-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.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" From: Colin Ian King In function ‘fwts_framework_strtrunc’, inlined from ‘fwts_framework_minor_test_progress’ at fwts_framework.c:470:3: fwts_framework.c:374:3: error: ‘strncpy’ output may be truncated copying between 0 and 247 bytes from a string of length 1023 [-Werror=stringop-truncation] 374 | strncpy(dest, src, max); | ^~~~~~~~~~~~~~~~~~~~~~~ In function ‘fwts_framework_strtrunc’, inlined from ‘fwts_framework_run_test.isra’ at fwts_framework.c:596:4: fwts_framework.c:374:3: error: ‘strncpy’ specified bound 1024 equals destination size [-Werror=stringop-truncation] 374 | strncpy(dest, src, max); | ^~~~~~~~~~~~~~~~~~~~~~~ In function ‘fwts_framework_strtrunc’, inlined from ‘fwts_framework_run_test.isra’ at fwts_framework.c:695:4: fwts_framework.c:374:3: error: ‘strncpy’ specified bound 1024 equals destination size [-Werror=stringop-truncation] 374 | strncpy(dest, src, max); | ^~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/lib/src/fwts_framework.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c index 698fa49a..8bc7b0e0 100644 --- a/src/lib/src/fwts_framework.c +++ b/src/lib/src/fwts_framework.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -371,9 +372,9 @@ static void fwts_framework_show_tests(fwts_framework *fw, const bool full) static void fwts_framework_strtrunc(char *dest, const char *src, size_t max) { if (src) { - strncpy(dest, src, max); + strlcpy(dest, src, max); if ((max > 3) && (strlen(src) > max)) { - dest[max-1] = 0; + dest[max-1] = '\0'; dest[max-2] = '.'; dest[max-3] = '.'; }