Commit graph

13687 commits

Author SHA1 Message Date
Miss Islington (bot)
ed01daf82e
[3.12] gh-131809: Upgrade vendored expat to 2.7.1 (GH-132192) (#132237)
* gh-131809: Upgrade vendored expat to 2.7.1 (GH-132192)
(cherry picked from commit c0de650024)

Co-authored-by: Gregory P. Smith <greg@krypto.org>

* make regen-sbom

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2025-04-07 21:21:02 +00:00
Miss Islington (bot)
81bc2cc7fd
[3.12] gh-122040: reword Modules/xxmodule.c module-level comment (GH-132201) (#132208)
gh-122040: reword `Modules/xxmodule.c` module-level comment (GH-132201)
(cherry picked from commit af8d1b9537)

Co-authored-by: Sonny Ding <93831983+sonnyding1@users.noreply.github.com>
2025-04-07 08:19:54 +00:00
Miss Islington (bot)
10f73f75c5
[3.12] gh-132075: Fix possible use of sockaddr structures with uninitialized members (GH-132076) (GH-132087)
Now all structure members are initialized with zeroes by default.
(cherry picked from commit 345baa77ba)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-04-04 14:29:12 +00:00
Serhiy Storchaka
6f6b8b4ac9
[3.12] gh-89039: Call subclass constructors in datetime.*.replace (GH-114780) (GH-131239)
When replace() method is called on a subclass of datetime, date or time,
properly call derived constructor. Previously, only the base class's
constructor was called.

Also, make sure to pass non-zero fold values when creating subclasses in
various methods. Previously, fold was silently ignored.
(cherry picked from commit 46190d9ea8)

Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
2025-04-02 20:35:16 +03:00
Miss Islington (bot)
afb3f33256
[3.12] gh-111178: Fix getsockaddrarg() undefined behavior (GH-131668) (GH-131977) (#131979)
[3.13] gh-111178: Fix getsockaddrarg() undefined behavior (GH-131668) (GH-131977)

gh-111178: Fix getsockaddrarg() undefined behavior (GH-131668)

Don't pass direct references to sockaddr members since their type may
not match PyArg_ParseTuple() types. Instead, use temporary 'int' and
'unsigned char' variables, and update sockaddr members afterwards.

On FreeBSD, treat BTPROTO_HCI node name as a bytes string,
not as an integer.
(cherry picked from commit c318a03b17)

Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 8cd29c2b53)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-01 14:56:56 +00:00
Miss Islington (bot)
5d4e891411
[3.12] gh-126033: fix UAF in xml.etree.ElementTree.Element.remove when concurrent mutations happen (GH-126124) (#131930)
gh-126033: fix UAF in `xml.etree.ElementTree.Element.remove` when concurrent mutations happen (GH-126124)
(cherry picked from commit bab1398a47)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-31 14:50:13 +02:00
Bénédikt Tran
f1689b61fe
[3.12] gh-126037: fix UAF in xml.etree.ElementTree.Element.find* when concurrent mutations happen (#127964) (#131932)
gh-126037: fix UAF in `xml.etree.ElementTree.Element.find*` when concurrent mutations happen (#127964)

We fix a use-after-free in the `find`, `findtext` and `findall` methods of `xml.etree.ElementTree.Element`
objects that can be triggered when the tag to find implements an `__eq__` method that mutates the
element being queried.

(cherry picked from commit c57623c221)
2025-03-31 14:47:22 +02:00
Steve Dower
dfb63723d2
gh-131423: Update to OpenSSL 3.0.16. (GH-131839)
The bin tag is 3.0.16.1 because we rebuilt without uplink support to fix gh-131804.
This PR also prevents making calls that are now unsafe without uplink, and updates
the tests to property interpret these failures as unsupported.
2025-03-28 15:29:20 +00:00
Donghee Na
940c937c13
[3.12] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (#131828) 2025-03-28 14:55:58 +01:00
Miss Islington (bot)
63a4273031
[3.12] gh-131418: remove unused legacy typedefs in {md5,sha1}module.c (GH-131420) (#131619)
gh-131418: remove unused legacy typedefs in `{md5,sha1}module.c` (GH-131420)

- Remove legacy typedefs `MD5_INT32` and `MD5_INT64` in `Modules/md5module.c`
- Remove legacy typedefs `SHA1_INT32` and `SHA1_INT64` in `Modules/sha1module.c`.

Those legacy typedefs were used to detect whether the host platform could
correctly implement MD5 and SHA-1, but this is no longer needed as we now
fallback to HACL* implementations.
(cherry picked from commit a9a399f0ec)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-23 11:39:46 +00:00
Miss Islington (bot)
38ef8d78bb
[3.12] gh-131261: Update libexpat to 2.7.0 (CVE-2024-8176) (GH-131361)
[3.13] gh-131261: Update libexpat to 2.7.0 (CVE-2024-8176)

(cherry picked from commit bb0268f60d)
(cherry picked from commit 6af54d298d)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2025-03-18 13:18:10 +01:00
Bénédikt Tran
304ef8440b
[3.12] gh-127667: refactor and improve _hashopenssl.c error branches (#131145) (#131348)
gh-127667: refactor and improve `_hashopenssl.c` error branches (#131145)

Refactor `_setException()` into different helpers that can be used separately:

- set_ssl_exception_from_errcode(): set an exception from an explicit SSL error code.
- raise_ssl_error(): set an exception from the last SSL error code or use a user-defined message.
- notify_ssl_error_occurred(): same as raise_ssl_error() but with a generic default message.

(cherry-picked from commit ac50ece6ce).
2025-03-18 10:16:26 +01:00
Alexandra
ba363894bb
[3.12] gh-131181: Assert that PyObject_stgdict isn't NULL for PyCData (#131188)
PyCData types have stgdict, so `PyObject_stgdict` can not return NULL.
Add an assert to make this clear.
2025-03-13 15:06:39 +00:00
Victor Stinner
3f226c5a7f
[3.12] gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044) (#131085)
gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044)

(cherry picked from commit de8818ae23)

Co-authored-by: Max Bachmann <kontakt@maxbachmann.de>
2025-03-11 11:55:13 +00:00
Petr Viktorin
8fe011af38
[3.12] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828) (GH-130876)
(cherry picked from commit 90130807d9)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-03-05 13:52:40 +02:00
Bénédikt Tran
d25da89953
[3.12] gh-127667: fix memory leaks in hashlib (GH-127668) (#130783)
gh-127667: fix memory leaks in `hashlib` (GH-127668)

- Correctly handle `NULL` values returned by `EVP_MD_CTX_md`.
- Correctly free resources in error branches.
- Consistently suppress `_setException()` return value when needed.
- Collapse `_setException() + return NULL` into a single statement.

(cherry-picked from commit 097846502b)
2025-03-03 10:44:42 +00:00
Petr Viktorin
a678d8e511
[3.12] gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test (GH-129406) (GH-130510) 2025-02-27 16:30:46 +01:00
Serhiy Storchaka
89a79fc919
[3.12] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556) (GH-130576)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().

(cherry picked from commit 0ef4ffeefd)
(cherry picked from commit 7c1b76fce8)
(cherry picked from commit 2ab7e1135a)
2025-02-26 17:20:47 +02:00
Bénédikt Tran
b1a188a7fa
[3.12] gh-130151: Fix reference leaks in _hashlib.hmac_{new,digest} (GH-130152) (#130539)
gh-130151: Fix reference leaks in `_hashlib.hmac_{new,digest}` (GH-130152)

* fix leak in `_hashlib.hmac_new`
* fix leak in `hmac_digest`
* fix exception type in `_hashlib.HMAC.copy`
(cherry picked from commit 071820113f)
2025-02-25 12:38:47 +01:00
Miss Islington (bot)
f314cc4db5
[3.12] gh-129838: Don't redefine _Py_NO_SANITIZE_UNDEFINED (GH-129839) (#130365)
gh-129838: Don't redefine _Py_NO_SANITIZE_UNDEFINED (GH-129839)

Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.
(cherry picked from commit 568db400ff)

Co-authored-by: Collin Funk <collin.funk1@gmail.com>
2025-02-20 16:20:27 +00:00
Erlend E. Aasland
02e00a7373
[3.12] gh-129603: Don't segfault if sqlite3.Row description is None (#129604) (#129924)
(cherry picked from commit 7e6ee50b6b)
2025-02-10 00:14:40 +00:00
Serhiy Storchaka
86451b146a
[3.12] gh-129502: Fix handling errors in ctypes callbacks (GH-129504) (#129639)
Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
(cherry picked from commit 9d63ae5fe5)
2025-02-04 15:04:46 +01:00
Miss Islington (bot)
6985b4be9b
[3.12] gh-129345: null check for indent syslogmodule (GH-129348) (#129443)
gh-129345: null check for indent syslogmodule (GH-129348)
(cherry picked from commit 25cf79a082)

Co-authored-by: Burkov Egor <xwooffie@gmail.com>
2025-02-04 00:24:56 +01:00
Victor Stinner
6186021c14
[3.12] gh-129539: Include sysexits.h before checking EX_OK (#129590) (#129609)
[3.13] gh-129539: Include sysexits.h before checking EX_OK (#129590)

Previously, the macro would be redefined when the header was included.

(cherry picked from commit 65f3432ac3)

Co-authored-by: Collin Funk <collin.funk1@gmail.com>
2025-02-03 12:00:10 +00:00
Victor Stinner
48f08fe6c8
[3.12] gh-111495: Add PyFile tests (#129449) (#129477) (#129501)
[3.13] gh-111495: Add PyFile tests (#129449) (#129477)

gh-111495: Add PyFile tests (#129449)

Add tests for the following functions in test_capi.test_file:

* PyFile_FromFd()
* PyFile_GetLine()
* PyFile_NewStdPrinter()
* PyFile_WriteObject()
* PyFile_WriteString()
* PyObject_AsFileDescriptor()

Remove test_embed.StdPrinterTests which became redundant.

(cherry picked from commit 4ca9fc08f8)
(cherry picked from commit 9a59a51733)
2025-01-31 10:27:35 +01:00
Miss Islington (bot)
cdaec318cb
[3.12] gh-129409: Fix Integer overflow - SEGV while writing data more than 2GB in CSV file (GH-129413) (#129437)
gh-129409: Fix Integer overflow -  SEGV while writing data more than 2GB in CSV file (GH-129413)
(cherry picked from commit 97b0ef05d9)

Co-authored-by: Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్  రెడ్డి) <thatiparthysreenivas@gmail.com>
2025-01-29 11:32:54 +00:00
Miss Islington (bot)
23faf5f2dc
[3.12] gh-129346: Handle allocation errors for SQLite aggregate context (GH-129347) (#129373)
(cherry picked from commit 379ab856f5)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
2025-01-27 17:33:18 +00:00
Victor Stinner
bb7c54d5ba
[3.12] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (#129217) (#129221)
[3.13] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (#129217)

gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191)

Support calling PyTraceMalloc_Track() and PyTraceMalloc_Untrack()
during late Python finalization.

* Call _PyTraceMalloc_Fini() later in Python finalization.
* Test also PyTraceMalloc_Untrack() without the GIL
* PyTraceMalloc_Untrack() now gets the GIL.
* Test also PyTraceMalloc_Untrack() in test_tracemalloc_track_race().

(cherry picked from commit 46c7e13c05)
(cherry picked from commit e3b3e01d6a)
2025-01-23 13:29:46 +00:00
Miss Islington (bot)
9b335cc810
[3.12] gh-111178: fix UBSan failures in Modules/_multiprocessing/semaphore.c (GH-129084) (#129101)
gh-111178: fix UBSan failures in `Modules/_multiprocessing/semaphore.c` (GH-129084)

fix UBSan failures for `SemLockObject`
(cherry picked from commit 5ed5572cac)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-01-20 21:00:09 +00:00
Miss Islington (bot)
7f68e7bf2a
[3.12] Fix a typo in syslog's error message (GH-129029) (#129050)
Fix a typo in `syslog`'s error message (GH-129029)
(cherry picked from commit 9b1c1817af)

Co-authored-by: Tomas R <tomas.roun8@gmail.com>
2025-01-20 10:28:55 +00:00
Victor Stinner
fceb8c31dd
[3.12] gh-111495: Add more tests on PyEval C APIs (#122789) (#128987) (#129023)
* Add Lib/test/test_capi/test_eval.py
* Add Modules/_testlimitedcapi/eval.c

(cherry picked from commit bf8b374639)

* gh-111495: Fix refleaks in test_capi.test_eval tests (#122851)

(cherry picked from commit b4a316087c)
(cherry picked from commit 430ccbc009)
2025-01-19 13:51:53 +00:00
Victor Stinner
6df22cbf60
[3.12] gh-128679: Fix tracemalloc.stop() race conditions (#128897) (#129022)
[3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897)

tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(),
PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check
tracemalloc_config.tracing after calling TABLES_LOCK().

_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(),
especially setting tracemalloc_config.tracing to 1.

Add a test using PyTraceMalloc_Track() to test tracemalloc.stop()
race condition.

Call _PyTraceMalloc_Init() at Python startup.

(cherry picked from commit 6b47499510)
2025-01-19 13:24:14 +00:00
Serhiy Storchaka
83de72e5ec
[3.12] gh-128911: Add tests on the PyImport C API (GH-128915) (GH-128960) (#128989)
* Add Modules/_testlimitedcapi/import.c
* Add Lib/test/test_capi/test_import.py
* Remove _testcapi.check_pyimport_addmodule(): tests already covered
  by newly added tests.
(cherry picked from commit 34ded1a1a1)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit d95ba9fa11)
2025-01-19 14:21:55 +01:00
Miss Islington (bot)
405f6d72bb
[3.12] gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128977)
(cherry picked from commit 4dade055f4)

Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
2025-01-18 10:14:07 +00:00
Miss Islington (bot)
dfd75dfeed
[3.12] gh-58689: Fix os.kill() error handling on Windows (GH-128932) (#128938)
gh-58689: Fix os.kill() error handling on Windows (GH-128932)
(cherry picked from commit 939df0f9f6)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-01-17 12:48:24 +00:00
Erlend E. Aasland
6b3371914c
[3.12] gh-127614: Correctly check for ttyname_r() in configure (#128503) (#128599)
(cherry picked from commit e08b28235a)

PR #14868 replaced the ttyname() call with ttyname_r(), but the old
check remained.
2025-01-07 22:05:42 +00:00
Miss Islington (bot)
84c8843490
[3.12] gh-123925: Fix building curses on platforms without libncursesw (GH-128405) (GH-128408)
(cherry picked from commit 8d16919a06)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-01-02 11:54:43 +00:00
Miss Islington (bot)
e7f8ba7444
gh-128217: Validate the normalized_environment variable instead of the similarly named function (GH-128220)
(cherry picked from commit 3ddd70ceaa)

Co-authored-by: Sergey Muraviov <smurav@mail.ru>
2024-12-24 13:25:16 +00:00
Bénédikt Tran
e0b61ffa38
[3.12] gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746) (GH-128027)
- Add a helper to set an error from locale-encoded `char*`
- Use the helper for gdbm & dlerror messages

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-17 14:53:16 +02:00
Bénédikt Tran
6ac578cf53
[3.12] gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) (GH-127764)
For dlsym(), a return value of NULL does not necessarily indicate
an error [1].

Therefore, to avoid using stale (or NULL) dlerror() values, we must:

 1. clear the previous error state by calling dlerror()
 2. call dlsym()
 3. call dlerror()

If the return value of dlerror() is not NULL, an error occured.

In ctypes we choose to treat a NULL return value from dlsym()
as a "not found" error. This is the same as the fallback
message we use on Windows, Cygwin or when getting/formatting
the error reason fails.

[1]: https://man7.org/linux/man-pages/man3/dlsym.3.html

Signed-off-by: Georgios Alexopoulos <grgalex42@gmail.com>
Signed-off-by: Georgios Alexopoulos <grgalex@ba.uoa.gr>
Co-authored-by: George Alexopoulos <giorgosalexo0@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-12-17 13:53:43 +02:00
Miss Islington (bot)
7f707fa6c6
[3.12] gh-127257: ssl: Raise OSError for ERR_LIB_SYS (GH-127361) (GH-127905)
gh-127257: ssl: Raise OSError for ERR_LIB_SYS (GH-127361)

From the ERR_raise manpage:

    ERR_LIB_SYS

        This "library code" indicates that a system error is
        being reported.  In this case, the reason code given
        to `ERR_raise()` and `ERR_raise_data()` *must* be
        `errno(3)`.

This PR only handles ERR_LIB_SYS for the high-lever error types
SSL_ERROR_SYSCALL and SSL_ERROR_SSL, i.e., not the ones where
OpenSSL indicates it has some more information about the issue.
(cherry picked from commit f4b31edf2d)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-12-16 15:43:57 +01:00
Victor Stinner
21c056ec27
[3.12] gh-127870: Detect recursive calls in ctypes _as_parameter_ handling (#127872) (#127918)
gh-127870: Detect recursive calls in ctypes _as_parameter_ handling (#127872)

(cherry picked from commit 6ff38fc4e2)
2024-12-13 13:21:30 +00:00
Miss Islington (bot)
a65475fb70
[3.12] gh-122431: Disallow negative values in readline.append_history_file (GH-122469) (#127642)
gh-122431: Disallow negative values in `readline.append_history_file` (GH-122469)
(cherry picked from commit 208b0fb645)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-05 18:15:30 +01:00
Victor Stinner
288d6d04ae
[3.12] gh-93312: Include <sys/pidfd.h> to get PIDFD_NONBLOCK (#127593) (#127631)
gh-93312: Include <sys/pidfd.h> to get PIDFD_NONBLOCK (#127593)

(cherry picked from commit fcbe6ecdb6)
2024-12-05 09:59:53 +00:00
Miss Islington (bot)
b49e902b81
[3.12] gh-126876: Fix socket internal_select() for large timeout (GH-126968) (#127003)
gh-126876: Fix socket internal_select() for large timeout (GH-126968)

If the timeout is larger than INT_MAX, replace it with INT_MAX, in
the poll() code path.

Add an unit test.
(cherry picked from commit b3687ad454)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-03 14:12:59 +00:00
Sergey B Kirpichev
34fe4af8a2
[3.12] gh-126618: fix repr(itertools.count(sys.maxsize)) (GH-127048) (#127510)
(cherry picked from commit 930ba0ce60)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-12-02 15:19:59 +01:00
Miss Islington (bot)
7d175caf21
[3.12] gh-127190: Fix local_setattro() error handling (GH-127366) (#127368)
gh-127190: Fix local_setattro() error handling (GH-127366)

Don't make the assumption that the 'name' argument is a string. Use
repr() to format the 'name' argument instead.
(cherry picked from commit 20657fbdb1)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-28 17:32:50 +00:00
Miss Islington (bot)
c3bb32de9d
[3.12] gh-124008: Fix calculation of the number of written bytes for the Windows console (GH-124059) (GH-127326)
Since MultiByteToWideChar()/WideCharToMultiByte() is not reversible if
the data contains invalid UTF-8 sequences, use binary search to
calculate the number of written bytes from the number of written
characters.

Also fix writing incomplete UTF-8 sequences.

Also fix handling of memory allocation failures.
(cherry picked from commit 3cf83d91a5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-11-27 16:00:30 +02:00
Miss Islington (bot)
a4d6b905dd
[3.12] gh-127182: Fix io.StringIO.__setstate__ crash when None is the first value (GH-127219) (#127263)
gh-127182: Fix `io.StringIO.__setstate__` crash when `None` is the first value (GH-127219)
(cherry picked from commit a2ee899682)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-25 17:51:21 +00:00
Serhiy Storchaka
f1e7424802
[3.12] gh-109746: Make _thread.start_new_thread delete state of new thread on its startup failure (GH-109761) (GH-127173)
If Python fails to start newly created thread
due to failure of underlying PyThread_start_new_thread() call,
its state should be removed from interpreter' thread states list
to avoid its double cleanup.

(cherry picked from commit ca3ea9ad05)

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
2024-11-22 19:56:39 +00:00