summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-21 23:36:36 (GMT)
committerGitHub <noreply@github.com>2021-04-21 23:36:36 (GMT)
commitf7bc44170b4bdd16c46b4b6acf7673ffc24dfb19 (patch)
tree79ae52602025fdf0bf6a5e7a4e9760897cdd2ffa
parent602eefef0bd0187049c2ab9071390f8573fc299a (diff)
downloadcpython-f7bc44170b4bdd16c46b4b6acf7673ffc24dfb19.zip
cpython-f7bc44170b4bdd16c46b4b6acf7673ffc24dfb19.tar.gz
cpython-f7bc44170b4bdd16c46b4b6acf7673ffc24dfb19.tar.bz2
bpo-26227: Fixes decoding of host names on Windows from ANSI instead of UTF-8 (GH-25510)
(cherry picked from commit dc516ef8395d15da0ab225eb0dceb2e0581f51ca) Co-authored-by: Steve Dower <steve.dower@python.org>
-rw-r--r--Misc/NEWS.d/next/Windows/2021-04-21-23-37-34.bpo-26227.QMY_eA.rst2
-rw-r--r--Modules/socketmodule.c2
2 files changed, 3 insertions, 1 deletions
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
index 0000000..d6826fb
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2021-04-21-23-37-34.bpo-26227.QMY_eA.rst
@@ -0,0 +1,2 @@
+Fixed decoding of host names in :func:`socket.gethostbyaddr` and
+:func:`socket.gethostbyname_ex`.
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 3e65dc0..5406f8b 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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);