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 17D4EA04AF; Sun, 3 May 2020 22:33:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 210151D531; Sun, 3 May 2020 22:32:38 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 3439A1D531 for ; Sun, 3 May 2020 22:32:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588537955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+G2G8xmuewZdTyMbmxIUuDphi8hXsG05WKfwnHLKfhQ=; b=LYTJd9ZzKuhHX4ksBIn4uaUbMwWgukKjHWLfrQcCCoY7v+x9PAbGpOgifre2B1atkoJ+ba urG+3chE52V+H4JW3w8Dn7/7EzyIIdZsPu8D+vErtY3/iGJcPPde0B7xa8Ik/jskdtvJnH zLpAtau5HFppa5wIr8BCRJL0kLGGth0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-gJwzfdDOOdCxh0ovaxj5RQ-1; Sun, 03 May 2020 16:32:31 -0400 X-MC-Unique: gJwzfdDOOdCxh0ovaxj5RQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E52EF107ACCA; Sun, 3 May 2020 20:32:29 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id B83E85798D; Sun, 3 May 2020 20:32:27 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Phil Yang , Lijian Zhang , Sunil Kumar Kori , Jerin Jacob Date: Sun, 3 May 2020 22:31:35 +0200 Message-Id: <20200503203135.6493-9-david.marchand@redhat.com> In-Reply-To: <20200503203135.6493-1-david.marchand@redhat.com> References: <20200503203135.6493-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-dev] [PATCH 8/8] 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" From: Phil Yang 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' \ =09may write a terminating nul past the end of the destination \ =09[-Werror=3Dformat-overflow=3D] 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 Acked-by: Sunil Kumar Kori Signed-off-by: David Marchand --- Changes since Phil patch: - removed single-use 'size' variable, - removed comment on PATH_MAX (this comment will get obsolete if trace->dir definition changes), - asprintf return code is not used, no need to store, --- lib/librte_eal/common/eal_common_trace_utils.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_ea= l/common/eal_common_trace_utils.c index 49cc8d7b1d..988d7593e1 100644 --- a/lib/librte_eal/common/eal_common_trace_utils.c +++ b/lib/librte_eal/common/eal_common_trace_utils.c @@ -244,22 +244,19 @@ int eal_trace_dir_args_save(char const *val) { =09struct trace *trace =3D trace_obj_get(); -=09uint32_t size =3D sizeof(trace->dir); -=09char *dir_path =3D NULL; +=09char *dir_path; =09int rc; =20 -=09if (strlen(val) >=3D size) { +=09if (strlen(val) >=3D sizeof(trace->dir) - 1) { =09=09trace_err("input string is too big"); =09=09return -ENAMETOOLONG; =09} =20 -=09dir_path =3D (char *)calloc(1, size); -=09if (dir_path =3D=3D NULL) { -=09=09trace_err("fail to allocate memory"); +=09if (asprintf(&dir_path, "%s/", val) =3D=3D -1) { +=09=09trace_err("failed to copy directory: %s", strerror(errno)); =09=09return -ENOMEM; =09} =20 -=09sprintf(dir_path, "%s/", val); =09rc =3D trace_dir_update(dir_path); =20 =09free(dir_path); --=20 2.23.0