Hello, Thank you for reporting this issue.
The problem appears to arise from a mismatch between the buffer capacity provided by gethostid() and the NUL-termination requirements of _hurd_get_host_config(). Although the hexadecimal representation of a 32-bit host ID requires at most eight characters, gethostid() subsequently passes the buffer to strtol(), which expects a NUL-terminated string. Consequently, the fixed-width representation does not eliminate the termination requirement. Increasing the buffer capacity from eight to nine bytes appears to be an appropriate and minimally invasive solution: char buf[9]; I would favor addressing this at the caller level rather than modifying the termination semantics of _hurd_get_host_config(), particularly given its use by other callers. It would also be appropriate to introduce a regression test verifying the round-trip consistency of sethostid() and gethostid(), with particular attention to host IDs whose hexadecimal representation occupies all eight characters. Regarding the historical behavior, examining the relevant revision history may help determine whether this is a regression or a pre-existing termination defect. These observations are based on static source analysis; I have not verified the proposed change at runtime. Best regards, Alperen Erkan --- diff --git a/sysdeps/mach/hurd/gethostid.c b/sysdeps/mach/hurd/gethostid.c --- a/sysdeps/mach/hurd/gethostid.c +++ b/sysdeps/mach/hurd/gethostid.c @@ - char buf[8]; + char buf[9]; On Sat, Nov 28, 2026 at 11:29 PM yelninei--- via Bug reports for the GNU Hurd <[email protected]> wrote: > Hi, > > I was playing around with get/sethostid and noticed the following: > > - After a successfull sethostid () /etc/hostid has the id in hex. > - gethostid fails to read it back. _hurd_get_host_config fails with > ENAMETOOLONG causing gethostid to return -1. > > The reason is that _hurd_get_host_config always tries to null-terminate > the given buffer however gethostid passes a buffer that is just large > enough to contain the contents as the id has a fixed size and a trailing > null is not really neccessary. > > Should that just use a bigger buffer? I dont know if this ever worked or > if the hostid was a casualty of making sure the return is null-terminated > which seems reasonable for the hostname as the hostid is not really used > much. > > Thanks, > Y. > >
