[LTP] [PATCH] gethostname: Fix ENAMETOOLONG on 64 character hostnames

Ian Whitfield ian.whitfield@canonical.com
Wed Jan 22 20:16:58 CET 2025


HOST_NAME_MAX does not include the null terminator, so the hostname
buffer in gethostname02.c needs an extra character of space to support
maximum length hostnames.

Signed-off-by: Ian Whitfield <ian.whitfield@canonical.com>
---
 testcases/kernel/syscalls/gethostname/gethostname02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/gethostname/gethostname02.c b/testcases/kernel/syscalls/gethostname/gethostname02.c
index 250e5f2fd..f792371ed 100644
--- a/testcases/kernel/syscalls/gethostname/gethostname02.c
+++ b/testcases/kernel/syscalls/gethostname/gethostname02.c
@@ -16,7 +16,7 @@
 
 static void verify_gethostname(void)
 {
-	char hostname[HOST_NAME_MAX];
+	char hostname[HOST_NAME_MAX + 1];
 	int real_length;
 
 	SAFE_GETHOSTNAME(hostname, sizeof(hostname));
-- 
2.43.0



More information about the ltp mailing list