bpo-26227: Fixes decoding of host names on Windows from ANSI instead of UTF-8 (GH-25510)

This commit is contained in:
Steve Dower 2021-04-22 00:18:20 +01:00 committed by GitHub
parent cdad2724e6
commit dc516ef839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -0,0 +1,2 @@
Fixed decoding of host names in :func:`socket.gethostbyaddr` and
:func:`socket.gethostbyname_ex`.

View File

@ -5508,7 +5508,7 @@ sock_decode_hostname(const char *name)
#ifdef MS_WINDOWS
/* Issue #26227: gethostbyaddr() returns a string encoded
* to the ANSI code page */
return PyUnicode_DecodeFSDefault(name);
return PyUnicode_DecodeMBCS(name, strlen(name), "surrogatepass");
#else
/* Decode from UTF-8 */
return PyUnicode_FromString(name);