From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 350C8A00BE; Tue, 28 Apr 2020 16:37:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 19B991D5F0; Tue, 28 Apr 2020 16:37:36 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id DC5E61D5ED for ; Tue, 28 Apr 2020 16:37:34 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1AF1831B; Tue, 28 Apr 2020 07:37:34 -0700 (PDT) Received: from phil-VirtualBox.arm.com (A010647.Arm.com [10.170.243.213]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0588E3F68F; Tue, 28 Apr 2020 07:37:31 -0700 (PDT) From: Phil Yang To: skori@marvell.com, dev@dpdk.org Cc: david.marchand@redhat.com, jerinj@marvell.com, lijian.zhang@arm.com, ruifeng.wang@arm.com, nd@arm.com Date: Tue, 28 Apr 2020 22:37:07 +0800 Message-Id: <1588084627-18772-1-git-send-email-phil.yang@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1588006058-10728-1-git-send-email-phil.yang@arm.com> References: <1588006058-10728-1-git-send-email-phil.yang@arm.com> Subject: [dpdk-dev] [PATCH v2] trace: fix build with gcc 10 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Prevent from writing beyond the allocated memory. GCC 10 compiling output: eal_common_trace_utils.c: In function 'eal_trace_dir_args_save': eal_common_trace_utils.c:290:24: error: '__builtin___sprintf_chk' \ may write a terminating nul past the end of the destination \ [-Werror=format-overflow=] 290 | sprintf(dir_path, "%s/", optarg); | ^ Fixes: 8af866df8d8c ("trace: add trace directory configuration parameter") Signed-off-by: Phil Yang Reviewed-by: Lijian Zhang Tested-by: Lijian Zhang --- v2: use asprintf instead of sprintf. lib/librte_eal/common/eal_common_trace_utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c index fce8892..2ffb8af 100644 --- a/lib/librte_eal/common/eal_common_trace_utils.c +++ b/lib/librte_eal/common/eal_common_trace_utils.c @@ -268,7 +268,7 @@ eal_trace_dir_args_save(char const *optarg) { struct trace *trace = trace_obj_get(); uint32_t size = sizeof(trace->dir); - char *dir_path = NULL; + char *dir_path; int rc; if (optarg == NULL) { @@ -276,18 +276,20 @@ eal_trace_dir_args_save(char const *optarg) return -EINVAL; } - if (strlen(optarg) >= size) { + /* the specified trace directory name cannot + * exceed PATH_MAX-1. + */ + if (strlen(optarg) >= (size - 1)) { trace_err("input string is too big"); return -ENAMETOOLONG; } - dir_path = (char *)calloc(1, size); - if (dir_path == NULL) { - trace_err("fail to allocate memory"); + rc = asprintf(&dir_path, "%s/", optarg); + if (rc == -1) { + trace_err("failed to copy directory: %s", strerror(errno)); return -ENOMEM; } - sprintf(dir_path, "%s/", optarg); rc = trace_dir_update(dir_path); free(dir_path); -- 2.7.4