DPDK patches and discussions
 help / color / mirror / Atom feed
From: Sunil Kumar Kori <skori@marvell.com>
To: Phil Yang <phil.yang@arm.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: "david.marchand@redhat.com" <david.marchand@redhat.com>,
	"Jerin Jacob Kollanukkaran" <jerinj@marvell.com>,
	"lijian.zhang@arm.com" <lijian.zhang@arm.com>,
	"ruifeng.wang@arm.com" <ruifeng.wang@arm.com>,
	"nd@arm.com" <nd@arm.com>
Subject: Re: [dpdk-dev] [EXT] [PATCH v2] trace: fix build with gcc 10
Date: Thu, 30 Apr 2020 13:51:56 +0000	[thread overview]
Message-ID: <BY5PR18MB3105B658B09E4644CC075E7EB4AA0@BY5PR18MB3105.namprd18.prod.outlook.com> (raw)
In-Reply-To: <1588084627-18772-1-git-send-email-phil.yang@arm.com>

Looks good to me.

Regards
Sunil Kumar Kori

>-----Original Message-----
>From: Phil Yang <phil.yang@arm.com>
>Sent: Tuesday, April 28, 2020 8:07 PM
>To: Sunil Kumar Kori <skori@marvell.com>; dev@dpdk.org
>Cc: david.marchand@redhat.com; Jerin Jacob Kollanukkaran
><jerinj@marvell.com>; lijian.zhang@arm.com; ruifeng.wang@arm.com;
>nd@arm.com
>Subject: [EXT] [PATCH v2] trace: fix build with gcc 10
>
>External Email
>
>----------------------------------------------------------------------
>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 <phil.yang@arm.com>
>Reviewed-by: Lijian Zhang <lijian.zhang@arm.com>
>Tested-by: Lijian Zhang <lijian.zhang@arm.com>

Acked-by: Sunil Kumar Kori <skori@marvell.com>
>---
>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


      reply	other threads:[~2020-04-30 13:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 16:47 [dpdk-dev] [PATCH] " Phil Yang
2020-04-27 16:58 ` Stephen Hemminger
2020-04-28  7:15   ` Phil Yang
2020-04-28  3:48 ` [dpdk-dev] [EXT] " Sunil Kumar Kori
2020-04-28  7:00   ` Phil Yang
2020-04-28 10:52     ` Sunil Kumar Kori
2020-04-28 13:50       ` Phil Yang
2020-04-28 14:37 ` [dpdk-dev] [PATCH v2] " Phil Yang
2020-04-30 13:51   ` Sunil Kumar Kori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BY5PR18MB3105B658B09E4644CC075E7EB4AA0@BY5PR18MB3105.namprd18.prod.outlook.com \
    --to=skori@marvell.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=lijian.zhang@arm.com \
    --cc=nd@arm.com \
    --cc=phil.yang@arm.com \
    --cc=ruifeng.wang@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).