casaroli opened a new pull request, #20928:
URL: https://github.com/apache/nuttx/pull/20928

   ## Summary
   
   Two changes to the host name size, one commit each:
   
   - **`uname()` cut the host name.** `HOST_NAME_MAX` is the maximum length of 
a host name without the terminating null 
([`<limits.h>`](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/limits.h.html)),
 and the host name buffer of libc has `HOST_NAME_MAX + 1` bytes. But 
`utsname.nodename` had only `HOST_NAME_MAX` bytes, so `uname()` returned at 
most `HOST_NAME_MAX - 1` bytes of the name. The field now has `HOST_NAME_MAX + 
1` bytes, and `uname()` gives the size of the field to `gethostname()`, which 
always ends the copy with a null.
   - **`HOST_NAME_MAX` was fixed at 32.** POSIX requires at least 255 
(`_POSIX_HOST_NAME_MAX`), so a system that needs longer host names could not 
have them. The new `CONFIG_HOST_NAME_MAX`, next to `CONFIG_NAME_MAX` and 
`CONFIG_PATH_MAX`, sets it. The default is 32, so nothing changes unless a 
configuration sets it.
   
   ## Impact
   
   - `struct utsname` is one byte larger (`nodename` has 33 bytes with the 
default). Programs built with the old header must be built again.
   - No other change with the default. A configuration that sets 
`CONFIG_HOST_NAME_MAX=255` gets POSIX host names; the host name buffer and 
every `struct utsname` then grow by 223 bytes.
   - All build modes and architectures. Documentation: the Kconfig help of the 
new option.
   
   ## Testing
   
   Test program `hostmax.c` on `qemu-armv8a:knsh` (QEMU with HVF): it sets a 
host name of exactly `HOST_NAME_MAX` bytes and checks the size of 
`utsname.nodename`, `gethostname()` and `uname()`.
   
   | | master | this PR | this PR, `CONFIG_HOST_NAME_MAX=255` |
   |---|---|---|---|
   | `sizeof(utsname.nodename)` | 32 (FAIL) | 33 (PASS) | 256 (PASS) |
   | `gethostname()` length | 32 (PASS) | 32 (PASS) | 255 (PASS) |
   | `uname()` `nodename` length | 31 (FAIL) | 32 (PASS) | 255 (PASS) |
   | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | status 0 | status 0 | 
status 0 |
   
   Build, each OK: `qemu-armv8a:nsh` (flat, arm64), `qemu-armv8a:knsh` (kernel, 
arm64), `rv-virt:knsh64` (kernel, rv64), `rv-virt:pnsh64` (protected, rv64), 
`lm3s6965-ek:qemu-protected` (protected, armv7-m). No new warnings.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to