]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-26227: Fixes decoding of host names on Windows from ANSI instead of UTF-8 (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 21 Apr 2021 23:36:36 +0000 (16:36 -0700)
committerGitHub <noreply@github.com>
Wed, 21 Apr 2021 23:36:36 +0000 (16:36 -0700)
(cherry picked from commit dc516ef8395d15da0ab225eb0dceb2e0581f51ca)

Co-authored-by: Steve Dower <steve.dower@python.org>
Misc/NEWS.d/next/Windows/2021-04-21-23-37-34.bpo-26227.QMY_eA.rst [new file with mode: 0644]
Modules/socketmodule.c

diff --git a/Misc/NEWS.d/next/Windows/2021-04-21-23-37-34.bpo-26227.QMY_eA.rst b/Misc/NEWS.d/next/Windows/2021-04-21-23-37-34.bpo-26227.QMY_eA.rst
new file mode 100644 (file)
index 0000000..d6826fb
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed decoding of host names in :func:`socket.gethostbyaddr` and
+:func:`socket.gethostbyname_ex`.
index 3e65dc027a38ca2da5f3ba5e2cda746303fa6868..5406f8b46f243f153b8c30d6cc2d19832a04a200 100644 (file)
@@ -5474,7 +5474,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);