From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: david.marchand@redhat.com, Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [PATCH v4 02/11] mem: avoid hugepage path overflow
Date: Thu, 5 Feb 2026 22:27:34 +0100 [thread overview]
Message-ID: <20260205213044.702908-3-thomas@monjalon.net> (raw)
In-Reply-To: <20260205213044.702908-1-thomas@monjalon.net>
When constructing hugepage path, allocate the variable
to avoid a possible overflow which was detected in debug build:
In function 'find_numasocket':
lib/eal/linux/eal_memory.c:450:31:
error: 'snprintf' output may be truncated
before the last format character [-Werror=format-truncation=]
lib/eal/linux/eal_memory.c:449:9:
note: 'snprintf' output 2 or more bytes (assuming 4097)
into a destination of size 4096
449 | snprintf(hugedir_str, sizeof(hugedir_str),
450 | "%s/%s", hpi->hugedir, eal_get_hugefile_prefix());
This is a new warning (format-truncation) enabled in DPDK 26.03.
Bugzilla ID: 1878
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
lib/eal/linux/eal_memory.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c
index 7c4197a5b8..ceda9c3246 100644
--- a/lib/eal/linux/eal_memory.c
+++ b/lib/eal/linux/eal_memory.c
@@ -436,8 +436,9 @@ find_numasocket(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
unsigned i, hp_count = 0;
uint64_t virt_addr;
char buf[BUFSIZ];
- char hugedir_str[PATH_MAX];
+ char *hugedir_str;
FILE *f;
+ int ret;
f = fopen("/proc/self/numa_maps", "r");
if (f == NULL) {
@@ -446,8 +447,14 @@ find_numasocket(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
return 0;
}
- snprintf(hugedir_str, sizeof(hugedir_str),
- "%s/%s", hpi->hugedir, eal_get_hugefile_prefix());
+ ret = asprintf(&hugedir_str, "%s/%s",
+ hpi->hugedir, eal_get_hugefile_prefix());
+ if (ret < 0) {
+ EAL_LOG(ERR, "%s(): failed to store hugepage path", __func__);
+ goto error;
+ }
+
+ ret = -1;
/* parse numa map */
while (fgets(buf, sizeof(buf), f) != NULL) {
@@ -503,12 +510,11 @@ find_numasocket(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
if (hp_count < hpi->num_pages[0])
goto error;
- fclose(f);
- return 0;
-
+ ret = 0;
error:
+ free(hugedir_str);
fclose(f);
- return -1;
+ return ret;
}
static int
--
2.52.0
next prev parent reply other threads:[~2026-02-05 21:31 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-12 21:53 [dpdk-dev] [PATCH] devtools: test different build types Thomas Monjalon
2021-05-21 15:03 ` David Marchand
2021-07-23 20:26 ` Andrew Rybchenko
2021-08-02 22:45 ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
2021-08-08 12:51 ` [dpdk-dev] [PATCH v3 0/5] more build tests Thomas Monjalon
2021-08-08 12:51 ` [dpdk-dev] [PATCH v3 1/5] net/qede: fix minsize build Thomas Monjalon
2021-08-09 5:15 ` [dpdk-dev] [EXT] " Devendra Singh Rawat
2021-08-09 7:11 ` Rasesh Mody
2021-09-15 15:16 ` David Marchand
2021-08-08 12:51 ` [dpdk-dev] [PATCH v3 2/5] regex/mlx5: " Thomas Monjalon
2021-08-11 8:48 ` Ruifeng Wang
2021-08-08 12:51 ` [dpdk-dev] [PATCH v3 3/5] vdpa/mlx5: " Thomas Monjalon
2021-08-09 6:43 ` Matan Azrad
2021-08-11 8:48 ` Ruifeng Wang
2021-08-08 12:51 ` [dpdk-dev] [PATCH v3 4/5] test/crypto: " Thomas Monjalon
2021-08-11 8:48 ` Ruifeng Wang
2021-08-08 12:51 ` [dpdk-dev] [PATCH v3 5/5] devtools: test different build types Thomas Monjalon
2024-08-15 16:26 ` Stephen Hemminger
2021-09-15 20:27 ` [dpdk-dev] [PATCH v3 0/5] more build tests Ferruh Yigit
2021-09-16 7:05 ` David Marchand
2026-01-28 11:58 ` [PATCH v4 0/4] " Thomas Monjalon
2026-01-28 11:58 ` [PATCH v4 1/4] bus/pci: fix unmap on failure in multi-process Thomas Monjalon
2026-01-28 14:11 ` Thomas Monjalon
2026-01-28 11:58 ` [PATCH v4 2/4] argparse: fix minsize build Thomas Monjalon
2026-01-29 1:35 ` fengchengwen
2026-01-28 11:58 ` [PATCH v4 3/4] mldev: " Thomas Monjalon
2026-01-28 11:58 ` [PATCH v4 4/4] devtools: test different build types Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 00/11] more build tests Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 01/11] mem: check fbarray name truncation in secondary process Thomas Monjalon
2026-02-05 21:27 ` Thomas Monjalon [this message]
2026-02-06 8:12 ` [PATCH v4 02/11] mem: avoid hugepage path overflow David Marchand
2026-02-06 9:59 ` Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 03/11] argparse: fix minsize build Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 04/11] mldev: " Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 05/11] bus/pci: " Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 06/11] power/intel_pstate: " Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 07/11] net/bnxt/tf_ulp: " Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 08/11] net/iavf: " Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 09/11] ci: fix debug build type Thomas Monjalon
2026-02-06 8:23 ` David Marchand
2026-02-05 21:27 ` [PATCH v4 10/11] devtools: test different build types Thomas Monjalon
2026-02-05 21:27 ` [PATCH v4 11/11] ci: check minsize build type in GHA Thomas Monjalon
2026-02-06 8:29 ` David Marchand
2026-02-06 9:57 ` [PATCH v4 00/11] more build tests 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=20260205213044.702908-3-thomas@monjalon.net \
--to=thomas@monjalon.net \
--cc=anatoly.burakov@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.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