[Python-checkins] bpo-26227: Fixes decoding of host names on Windows from ANSI instead of UTF-8 (GH-25510)
miss-islington
webhook-mailer at python.org
Wed Apr 21 19:43:44 EDT 2021
https://github.com/python/cpython/commit/d8576b1d15155688a67baac24c15254700bdd3b7
commit: d8576b1d15155688a67baac24c15254700bdd3b7
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-04-21T16:43:40-07:00
summary:
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 at python.org>
files:
A Misc/NEWS.d/next/Windows/2021-04-21-23-37-34.bpo-26227.QMY_eA.rst
M 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
index 00000000000000..d6826fb39706bd
--- /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 be75e681d45d99..89531851c85756 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -5557,7 +5557,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);
More information about the Python-checkins
mailing list