diff options
| author | Eli Zaretskii | 2026-02-27 17:55:05 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2026-02-27 17:55:05 +0200 |
| commit | 76c7c867d6215d9126ed8c52c0db96d72c4e2f09 (patch) | |
| tree | aa325c96c69f7ebab503917e408653d5b2044bf5 /src | |
| parent | 13cc7c2b5406e9a2f4a6fbb89730020228e9f7f1 (diff) | |
| download | emacs-76c7c867d6215d9126ed8c52c0db96d72c4e2f09.tar.gz emacs-76c7c867d6215d9126ed8c52c0db96d72c4e2f09.zip | |
Fix bug on MS-Windows with frame title when system-name is non-ASCII
* src/w32.c (sys_gethostname): Convert system name to UTF-8.
Ensure the buffer passed to 'gethostname' is large enough.
(Bug#80472)
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 33 |
1 files changed, 23 insertions, 10 deletions
| @@ -8264,25 +8264,38 @@ sys_inet_addr (const char * cp) | |||
| 8264 | pfn_inet_addr (cp) : INADDR_NONE; | 8264 | pfn_inet_addr (cp) : INADDR_NONE; |
| 8265 | } | 8265 | } |
| 8266 | 8266 | ||
| 8267 | /* Wrapper for gethostname. Note: NAMELEN is the space available in | ||
| 8268 | NAME excluding the terminating null. */ | ||
| 8267 | int | 8269 | int |
| 8268 | sys_gethostname (char * name, int namelen) | 8270 | sys_gethostname (char * name, int namelen) |
| 8269 | { | 8271 | { |
| 8272 | int retval; | ||
| 8273 | int nlen = namelen; | ||
| 8274 | char sname[256+1]; | ||
| 8275 | |||
| 8270 | if (winsock_lib != NULL) | 8276 | if (winsock_lib != NULL) |
| 8271 | { | 8277 | { |
| 8272 | int retval; | ||
| 8273 | |||
| 8274 | check_errno (); | 8278 | check_errno (); |
| 8275 | retval = pfn_gethostname (name, namelen); | 8279 | retval = pfn_gethostname (sname, sizeof(sname)); |
| 8276 | if (retval == SOCKET_ERROR) | 8280 | if (retval == SOCKET_ERROR) |
| 8277 | set_errno (); | 8281 | set_errno (); |
| 8278 | return retval; | ||
| 8279 | } | 8282 | } |
| 8280 | 8283 | else if (sizeof(sname) > MAX_COMPUTERNAME_LENGTH) | |
| 8281 | if (namelen > MAX_COMPUTERNAME_LENGTH) | 8284 | retval = !GetComputerNameA (sname, (DWORD *)&nlen); |
| 8282 | return !GetComputerName (name, (DWORD *)&namelen); | 8285 | else |
| 8283 | 8286 | { | |
| 8284 | errno = EFAULT; | 8287 | retval = SOCKET_ERROR; |
| 8285 | return SOCKET_ERROR; | 8288 | errno = EFAULT; |
| 8289 | } | ||
| 8290 | /* The rest of the code wants the name in UTF-8. The host name is not | ||
| 8291 | a file name, but it's encoded in the ANSI codepage and its size | ||
| 8292 | must be at most 256 characters. So treating it as a file name | ||
| 8293 | should be okay. */ | ||
| 8294 | char hostname[MAX_UTF8_PATH]; | ||
| 8295 | filename_from_ansi (sname, hostname); | ||
| 8296 | strncpy (name, hostname, namelen); | ||
| 8297 | name[namelen] = '\0'; | ||
| 8298 | return retval; | ||
| 8286 | } | 8299 | } |
| 8287 | 8300 | ||
| 8288 | struct hostent * | 8301 | struct hostent * |