public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Maks Mishin <maks.mishinfz@gmail.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: Maks Mishin <maks.mishinFZ@gmail.com>, netdev@vger.kernel.org
Subject: [PATCH] ifstat: Add NULL pointer check for result of ll_index_to_name()
Date: Sat,  6 Jan 2024 23:10:10 +0300	[thread overview]
Message-ID: <20240106201010.29461-1-maks.mishinFZ@gmail.com> (raw)

Result of ll_index_to_name() function do not being checked for NULL
pointer before using in strdup() function.
Add intermediate variable `name` for result of ll_index_to_name()
function. Function result -1 when `name` is NULL.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 misc/ifstat.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/misc/ifstat.c b/misc/ifstat.c
index f6f9ba50..e6c38812 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -129,7 +129,12 @@ static int get_nlmsg_extended(struct nlmsghdr *m, void *arg)
 		abort();
 
 	n->ifindex = ifsm->ifindex;
-	n->name = strdup(ll_index_to_name(ifsm->ifindex));
+	
+	const char* name = ll_index_to_name(ifsm->ifindex);
+	if (name == NULL) {
+		return -1;
+	}
+	n->name = strdup(name);
 
 	if (sub_type == NO_SUB_TYPE) {
 		memcpy(&n->val, RTA_DATA(tb[filter_type]), sizeof(n->val));
-- 
2.34.1


             reply	other threads:[~2024-01-06 20:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-06 20:10 Maks Mishin [this message]
2024-01-06 22:14 ` [PATCH] ifstat: Add NULL pointer check for result of ll_index_to_name() Stephen Hemminger

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=20240106201010.29461-1-maks.mishinFZ@gmail.com \
    --to=maks.mishinfz@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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