DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Stephen Hemminger <sthemmin@microsoft.com>
Subject: [PATCH v3] eal: simplify argv[0] handling
Date: Wed,  9 Feb 2022 12:41:51 -0800	[thread overview]
Message-ID: <20220209204151.443418-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20220202194738.404876-1-stephen@networkplumber.org>

The rte_eal_init function looks at argv[0] to determine
the program name to pass to the log init function.
But in corner cases argv[0] maybe NULL leading to a SEGV.

The code here is just using argv[0] to generate logid which
does not have to be in a static string, openlog() will handle
a const char pointer.

Simple workaround for argv[0] being NULL is to pass NULL
to openlog() and let it handle it. Both glibc, and musl
handle this case.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---

v3 - redo to make this limited to just the null argv[0] bug

 lib/eal/linux/eal.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 9c8395ab14d0..c0ff325c4ce9 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -966,8 +966,7 @@ rte_eal_init(int argc, char **argv)
 	pthread_t thread_id;
 	static uint32_t run_once;
 	uint32_t has_run = 0;
-	const char *p;
-	static char logid[PATH_MAX];
+	const char *logid = NULL;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 	bool phys_addrs;
@@ -989,8 +988,12 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	p = strrchr(argv[0], '/');
-	strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
+	if (argv && argv[0]) {
+		const char *p = strrchr(argv[0], '/');
+
+		logid = p ? p + 1 : argv[0];
+	}
+
 	thread_id = pthread_self();
 
 	eal_reset_internal_config(internal_conf);
-- 
2.34.1


      parent reply	other threads:[~2022-02-09 20:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 19:47 [PATCH] eal: remove unnecessary " Stephen Hemminger
2022-02-09 14:58 ` Thomas Monjalon
2022-02-09 15:36   ` Stephen Hemminger
2022-02-09 15:45   ` Stephen Hemminger
2022-02-09 18:51     ` Thomas Monjalon
2022-02-09 19:29       ` Stephen Hemminger
2022-02-10  7:57         ` Thomas Monjalon
2022-02-09 15:54 ` [PATCH v2] Subject: " Stephen Hemminger
2022-02-09 20:41 ` Stephen Hemminger [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=20220209204151.443418-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=sthemmin@microsoft.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).