microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.48k stars 822 forks source link

Unicode Windows hostnames invalid in Linux/WSL #8386

Open cerebrate opened 2 years ago

cerebrate commented 2 years ago

Version

Windows 11 Dev Channel build 22616.1

WSL Version

Kernel Version

5.10.102.1-microsoft-standard-WSL2

Distro Version

Ubuntu 16.04

Other Software

No response

Repro Steps

This is an issue I'm reporting based on a specific issue found when using genie under WSL (see here for original issue: https://github.com/arkane-systems/genie/issues/268 ), but the underlying problem is not specific to any particular application.

  1. Set the Windows computer name (specifically, DNS host name) to a name containing Unicode characters, such as '机械革命'.

(This is permitted per https://docs.microsoft.com/en-us/troubleshoot/windows-server/identity/naming-conventions-for-computer-domain-site-ou#dns-host-names provided the network it is on uses Microsoft DNS.)

  1. Start a WSL distribution.

Expected Behavior

The Unicode Windows hostname should be replaced with a translation (such as Punycode, as used for internationalized domain names generally) of the Unicode Windows hostname, or failing that a generic replacement hostname, that is compliant with Linux / RFC952 / RFC 1123 standard for permitted hostnames.

Actual Behavior

The WSL hostname matches the Windows one. This gives rise to assorted Unicode errors, etc., in various applications since Unicode characters are not permitted in Linux hostnames, per hostname(7): https://www.man7.org/linux/man-pages/man7/hostname.7.html and other documentation. Such hostnames are also incompatible with native hostname management commands:

❯ sudo hostname 机械革命
hostname: the specified hostname is invalid
[1]    328332 exit 1     sudo hostname 机械革命

❯ sudo hostnamectl hostname --static 机械革命
Could not set static hostname: Invalid static hostname '机械革命'
[1]    328629 exit 1     sudo hostnamectl hostname --static 机械革命

Diagnostic Logs

No response

benhillis commented 2 years ago

Good call, we should probably sanitize the host name if it contains invalid characters.