Files
RustPython/crates
Jeong, YunWon a635d0b536 socket: accept a filesystem-encoded hostname in sethostname (#8437)
`socket.sethostname` took `PyUtf8StrRef`, so it rejected `bytes` outright and
refused a `str` carrying a surrogate escape. `socketmodule.c
socket_sethostname` accepts a bytes object directly, falls back to
`PyUnicode_FSConverter` for anything else, and hands the syscall the resulting
buffer and its length — the name is never required to be UTF-8.

Take `FsPath`, the converter `if_nametoindex` in this same module already uses,
and pass its bytes down. `host_env::socket::sethostname` correspondingly takes
`&[u8]` and builds the `OsStr` from them; `nix::unistd::sethostname` accepts
`AsRef<OsStr>` and passes pointer and length to the syscall, so nothing on the
path needs a NUL terminator or valid UTF-8.

`Lib/test/test_socket.py test_sethostname` covers this: it calls
`socket.sethostname(b'bar')` and asserts the hostname changed. The test is
skipped unless run as root, which is why the gap went unnoticed.

Assisted-by: Claude
2026-08-03 21:46:27 +09:00
..
2026-03-31 21:05:08 +09:00
2026-07-12 12:35:00 +00:00
2026-06-30 23:40:29 +09:00
2026-03-31 21:05:08 +09:00
2026-08-03 17:52:42 +09:00