From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <ferruh.yigit@amd.com>,
Keith Wiles <keith.wiles@intel.com>,
Ciara Power <ciara.power@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>,
Jeff Guo <jia.guo@intel.com>,
Jianfeng Tan <jianfeng.tan@intel.com>
Cc: <dev@dpdk.org>
Subject: [PATCH v2 01/16] eal: verify strdup return value
Date: Fri, 10 Nov 2023 10:01:02 +0000 [thread overview]
Message-ID: <20231110100117.8350-2-fengchengwen@huawei.com> (raw)
In-Reply-To: <20231110100117.8350-1-fengchengwen@huawei.com>
Add verify strdup() return value logic.
Fixes: 293c53d8b23c ("eal: add telemetry callbacks")
Fixes: 0d0f478d0483 ("eal/linux: add uevent parse and process")
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/eal/common/eal_common_options.c | 24 ++++++++++++++++++++++--
lib/eal/linux/eal_dev.c | 3 +++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index a6d21f1cba..8b5a4632dd 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -226,6 +226,8 @@ eal_save_args(int argc, char **argv)
if (strcmp(argv[i], "--") == 0)
break;
eal_args[i] = strdup(argv[i]);
+ if (eal_args[i] == NULL)
+ goto error;
}
eal_args[i++] = NULL; /* always finish with NULL */
@@ -235,13 +237,31 @@ eal_save_args(int argc, char **argv)
eal_app_args = calloc(argc - i + 1, sizeof(*eal_args));
if (eal_app_args == NULL)
- return -1;
+ goto error;
- for (j = 0; i < argc; j++, i++)
+ for (j = 0; i < argc; j++, i++) {
eal_app_args[j] = strdup(argv[i]);
+ if (eal_app_args[j] == NULL)
+ goto error;
+ }
eal_app_args[j] = NULL;
return 0;
+
+error:
+ if (eal_app_args != NULL) {
+ i = 0;
+ while (eal_app_args[i] != NULL)
+ free(eal_app_args[i++]);
+ free(eal_app_args);
+ eal_app_args = NULL;
+ }
+ i = 0;
+ while (eal_args[i] != NULL)
+ free(eal_args[i++]);
+ free(eal_args);
+ eal_args = NULL;
+ return -1;
}
#endif
diff --git a/lib/eal/linux/eal_dev.c b/lib/eal/linux/eal_dev.c
index ac76f6174d..df3cd6b39a 100644
--- a/lib/eal/linux/eal_dev.c
+++ b/lib/eal/linux/eal_dev.c
@@ -181,7 +181,10 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
buf += 14;
i += 14;
strlcpy(pci_slot_name, buf, sizeof(subsystem));
+ free(event->devname);
event->devname = strdup(pci_slot_name);
+ if (event->devname == NULL)
+ return -1;
}
for (; i < length; i++) {
if (*buf == '\0')
--
2.17.1
next prev parent reply other threads:[~2023-11-10 10:05 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 10:01 [PATCH v2 00/16] " Chengwen Feng
2023-11-10 10:01 ` Chengwen Feng [this message]
2023-11-21 3:44 ` [PATCH v2 01/16] eal: " lihuisong (C)
2024-02-18 13:50 ` Thomas Monjalon
2023-11-10 10:01 ` [PATCH v2 02/16] bus/dpaa: " Chengwen Feng
2023-11-15 2:43 ` Sachin Saxena
2023-11-10 10:01 ` [PATCH v2 03/16] bus/fslmc: " Chengwen Feng
2023-11-15 2:43 ` Sachin Saxena
2023-11-10 10:01 ` [PATCH v2 04/16] bus/vdev: " Chengwen Feng
2023-11-21 3:36 ` lihuisong (C)
2023-11-10 10:01 ` [PATCH v2 05/16] dma/idxd: " Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 06/16] event/cnxk: " Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 07/16] net/failsafe: fix memory leak when parse args Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 08/16] net/nfp: verify strdup return value Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 09/16] app/dumpcap: " Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 10/16] app/pdump: " Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 11/16] app/test: " Chengwen Feng
2023-11-21 3:33 ` lihuisong (C)
2023-11-10 10:01 ` [PATCH v2 12/16] app/test-crypto-perf: " Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 13/16] app/test-dma-perf: " Chengwen Feng
2023-11-21 3:32 ` lihuisong (C)
2023-11-10 10:01 ` [PATCH v2 14/16] app/testpmd: " Chengwen Feng
2023-11-10 11:44 ` Ivan Malov
2023-11-21 3:32 ` lihuisong (C)
2023-11-10 10:01 ` [PATCH v2 15/16] examples/qos_sched: fix memory leak when parse args Chengwen Feng
2023-11-10 10:01 ` [PATCH v2 16/16] examples/vhost: verify strdup return value Chengwen Feng
2023-11-21 3:35 ` lihuisong (C)
2024-01-15 2:57 ` [PATCH v2 00/16] " fengchengwen
2024-02-18 16:01 ` Thomas Monjalon
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=20231110100117.8350-2-fengchengwen@huawei.com \
--to=fengchengwen@huawei.com \
--cc=bruce.richardson@intel.com \
--cc=ciara.power@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=jia.guo@intel.com \
--cc=jianfeng.tan@intel.com \
--cc=keith.wiles@intel.com \
--cc=thomas@monjalon.net \
/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).