From 10a09af910bac0ce9dc43591bc9eba036d60fa3b Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Mon, 25 May 2026 16:52:01 +0200 Subject: [PATCH 1/3] fix: check result of PyThread_allocate_lock for netdb_lock --- Modules/socketmodule.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 566989d648d2f7..3eaa8cf7548239 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -9293,6 +9293,9 @@ socket_exec(PyObject *m) /* Initialize gethostbyname lock */ #if defined(USE_GETHOSTBYNAME_LOCK) netdb_lock = PyThread_allocate_lock(); + if (netdb_lock == NULL) { + goto error; + } #endif #ifdef MS_WINDOWS From 51346fda895cb9084184577bd902aa098ef7978e Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Mon, 25 May 2026 17:01:25 +0200 Subject: [PATCH 2/3] misc: add news entry --- .../Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst diff --git a/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst new file mode 100644 index 00000000000000..99b1adf08046ea --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst @@ -0,0 +1,4 @@ +Fix crash in :mod:`socket` module initialization when :func:`PyThread_allocate_lock` +fails to allocate ``netdb_lock``: the ``NULL`` return value is now checked and a +:exc:`MemoryError` is raised instead of dereferencing a null pointer. Patch by +Thomas Kowalski. From 0ce8691f7bccf5c6cf73257058a86c5a6a0ac230 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Mon, 25 May 2026 23:12:50 +0200 Subject: [PATCH 3/3] review: update news entry --- .../Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst index 99b1adf08046ea..df9cd1b716ccf8 100644 --- a/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst +++ b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst @@ -1,4 +1 @@ -Fix crash in :mod:`socket` module initialization when :func:`PyThread_allocate_lock` -fails to allocate ``netdb_lock``: the ``NULL`` return value is now checked and a -:exc:`MemoryError` is raised instead of dereferencing a null pointer. Patch by -Thomas Kowalski. +Fix a possible crash in the :mod:`socket` module initialization.