[PATCH v5 3/8] test: avoid overflowing huge directory path

Stephen Hemminger
2025-11-21T17:10:11Z

Since the tests construct a mulit-part path in huge pages directory,
avoid overflowing the string buffer by limiting the possible
huge page directory. Can never happen in real life, but compiler
gives warnings about string overflow that it could.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
app/test/test_eal_flags.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index c2e6c00edb..1d1ca87e0f 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -172,7 +172,7 @@ process_hugefiles(const char * prefix, enum hugepage_action action)
struct dirent *dirent = NULL;

char hugefile_prefix[PATH_MAX] = {0};
- char hugedir[PATH_MAX] = {0};
+ char hugedir[PATH_MAX - NAME_MAX] = {0};
char line[PATH_MAX] = {0};

int fd, lck_result, result = 0;
@@ -222,7 +222,7 @@ process_hugefiles(const char * prefix, enum hugepage_action action)
break;
case HUGEPAGE_DELETE:
{
- char file_path[PATH_MAX] = {0};
+ char file_path[PATH_MAX + NAME_MAX] = {0};

snprintf(file_path, sizeof(file_path),
"%s/%s", hugedir, dirent->d_name);
@@ -873,7 +873,7 @@ test_no_huge_flag(void)
static int
test_misc_flags(void)
{
- char hugepath[PATH_MAX] = {0};
+ char hugepath[PATH_MAX - NAME_MAX] = {0};
char hugepath_dir[PATH_MAX] = {0};
char hugepath_dir2[PATH_MAX] = {0};
char hugepath_dir3[PATH_MAX] = {0};
--
2.51.0