[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240110205252.20870-1-maks.mishinFZ@gmail.com>
Date: Wed, 10 Jan 2024 23:52:52 +0300
From: Maks Mishin <maks.mishinfz@...il.com>
To: Stephen Hemminger <stephen@...workplumber.org>
Cc: Maks Mishin <maks.mishinFZ@...il.com>,
netdev@...r.kernel.org
Subject: [PATCH] ifstat: Add NULL pointer check for argument of strdup()
When calling a strdup() function its argument do not being checked
for NULL pointer.
Added NULL pointer checks in body of get_nlmsg_extended(), get_nlmsg() and
load_raw_data() functions.
Signed-off-by: Maks Mishin <maks.mishinFZ@...il.com>
---
misc/ifstat.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/misc/ifstat.c b/misc/ifstat.c
index f6f9ba50..ee301799 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));
@@ -175,7 +180,12 @@ static int get_nlmsg(struct nlmsghdr *m, void *arg)
if (!n)
abort();
n->ifindex = ifi->ifi_index;
- n->name = strdup(RTA_DATA(tb[IFLA_IFNAME]));
+ const char *name = RTA_DATA(tb[IFLA_IFNAME]);
+
+ if (name == NULL)
+ return -1;
+
+ n->name = strdup(name);
memcpy(&n->ival, RTA_DATA(tb[IFLA_STATS]), sizeof(n->ival));
memset(&n->rate, 0, sizeof(n->rate));
for (i = 0; i < MAXS; i++)
@@ -263,6 +273,9 @@ static void load_raw_table(FILE *fp)
abort();
*next++ = 0;
+ if (p == NULL)
+ abort();
+
n->name = strdup(p);
p = next;
--
2.34.1
Powered by blists - more mailing lists