This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7af07a38c0f8c558c295917bd913332b23f26f18 Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 23 14:44:04 2026 +0200 libs/libc/misc: Return the whole host name in uname(). HOST_NAME_MAX is the maximum size of a host name without the terminating null, and the host name buffer is HOST_NAME_MAX + 1 bytes. But utsname.nodename had only HOST_NAME_MAX bytes, so uname() cut a host name of HOST_NAME_MAX bytes by one byte. Give utsname.nodename HOST_NAME_MAX + 1 bytes, and let uname() pass the size of the field to gethostname(), which always ends the copy with a null. struct utsname is one byte larger. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/sys/utsname.h | 10 +++++----- libs/libc/misc/lib_utsname.c | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/sys/utsname.h b/include/sys/utsname.h index 2b099067776..bf137d75c0d 100644 --- a/include/sys/utsname.h +++ b/include/sys/utsname.h @@ -66,11 +66,11 @@ struct utsname { - char sysname[SYS_NAMELEN]; /* Name of OS */ - char nodename[HOST_NAME_MAX]; /* Name of this network node */ - char release[SYS_NAMELEN]; /* Release level */ - char version[VERSION_NAMELEN]; /* Version level */ - char machine[SYS_NAMELEN]; /* Machine hardware */ + char sysname[SYS_NAMELEN]; /* Name of OS */ + char nodename[HOST_NAME_MAX + 1]; /* Name of this network node */ + char release[SYS_NAMELEN]; /* Release level */ + char version[VERSION_NAMELEN]; /* Version level */ + char machine[SYS_NAMELEN]; /* Machine hardware */ }; /**************************************************************************** diff --git a/libs/libc/misc/lib_utsname.c b/libs/libc/misc/lib_utsname.c index c692297db75..c454a55f008 100644 --- a/libs/libc/misc/lib_utsname.c +++ b/libs/libc/misc/lib_utsname.c @@ -100,8 +100,7 @@ int uname(FAR struct utsname *name) /* Get the hostname */ - ret = gethostname(name->nodename, HOST_NAME_MAX); - name->nodename[HOST_NAME_MAX - 1] = '\0'; + ret = gethostname(name->nodename, sizeof(name->nodename)); strlcpy(name->release, CONFIG_VERSION_STRING, sizeof(name->release));
