Commit Graph

12953 Commits

Author SHA1 Message Date
Miss Islington (bot) 7fefed091a
[3.11] gh-110590: Fix a bug where _sre.compile would overwrite exceptions (GH-110591) (#110614)
TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
(cherry picked from commit 344d3a222a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-10-10 10:48:07 +00:00
Miss Islington (bot) 194272179d
[3.11] gh-78469: Declare missing sethostname for Solaris 10 (GH-109447) (#110581)
Add OS version specific macro for Solaris: Py_SUNOS_VERSION.
(cherry picked from commit 3b1580af07)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
2023-10-10 10:06:18 +00:00
Bo Anderson 9e9df93ffc
[3.11] gh-109191: Fix build with newer editline (gh-110239) (#110575)
(cherry picked from commit f4cb0d27cc)
2023-10-09 19:42:25 +00:00
Miss Islington (bot) 34c7793cd0
[3.11] gh-110365: Fix error overwrite in `termios.tcsetattr` (GH-110366) (#110390)
(cherry picked from commit 2bbbab212f)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Erlend E. Aasland <erlend@python.org>
2023-10-05 14:21:34 +02:00
Victor Stinner 190e8fbfb7
[3.11] gh-108851: Fix support.get_recursion_available() for USE_STACKCHECK (#110127)
Add _testcapi.USE_STACKCHECK.

USE_STACKCHECK on using on Windows 32-bit.
2023-09-29 23:54:46 +02:00
Victor Stinner 615d7fc34a
[3.11] gh-110052: Fix faulthandler for freed tstate (#110069) (#110072)
gh-110052: Fix faulthandler for freed tstate (#110069)

faulthandler now detected freed interp and freed tstate, and no
longer dereference them.

Backport to 3.11: add pycore_pymem.h include to traceback.c.

(cherry picked from commit 2e37a38bcb)
2023-09-29 02:43:28 +00:00
Miss Islington (bot) 8ed9bda519
[3.11] gh-109098: Fuzz re module instead of internal sre (GH-109911) (GH-109933)
* Fix c-analyzer globals test failure
* Put globals exception in ignored.tsv
(cherry picked from commit a829356f86)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
2023-09-27 09:15:40 +03:00
Miss Islington (bot) f764abb375
[3.11] gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (GH-109629) (#109897)
gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (GH-109629)

---------

(cherry picked from commit 0eb98837b6)

Co-authored-by: Antoine Pitrou <antoine@python.org>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2023-09-26 12:21:52 +00:00
Miss Islington (bot) 97f7e9d5d6
[3.11] gh-109631: Allow interruption of short repeated regex matches (GH-109867) (GH-109885)
Counting for signal checking now continues in new match from the point where
it ended in the previous match instead of starting from 0.
(cherry picked from commit 8ac2085b80)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-09-26 08:19:29 +00:00
Victor Stinner 0afae8928b
[3.11] gh-109795: `_thread.start_new_thread`: allocate thread bootstate usin… (#109852)
gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw memory allocator (#109808)

(cherry picked from commit 1b8f2366b3)

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
2023-09-25 18:12:43 +02:00
Victor Stinner 0c79353e11
[3.11] gh-109613: _pystat_fromstructstat() checks for exceptions (#109618) (#109668)
gh-109613: _pystat_fromstructstat() checks for exceptions (#109618)

Fix os.stat() and os.DirEntry.stat(): check for exceptions.
Previously, on Python built in debug mode, these functions could
trigger a fatal Python error (and abort the process) when a function
succeeded with an exception set.

_pystat_fromstructstat() now exits immediately if an exception is
raised, rather only checking for exceptions at the end. It fix
following fatal error in fill_time():

    Fatal Python error: _Py_CheckSlotResult:
    Slot * of type int succeeded with an exception set

(cherry picked from commit d4cea794a7)
2023-09-21 18:00:38 +00:00
Victor Stinner 82a18069a1
[3.11] gh-108987: Fix _thread.start_new_thread() race condition (#109135) (#109272)
gh-108987: Fix _thread.start_new_thread() race condition (#109135)

Fix _thread.start_new_thread() race condition. If a thread is created
during Python finalization, the newly spawned thread now exits
immediately instead of trying to access freed memory and lead to a
crash.

thread_run() calls PyEval_AcquireThread() which checks if the thread
must exit. The problem was that tstate was dereferenced earlier in
_PyThreadState_Bind() which leads to a crash most of the time.

Move _PyThreadState_CheckConsistency() from thread_run() to
_PyThreadState_Bind().

(cherry picked from commit 517cd82ea7)
2023-09-11 19:33:08 +02:00
Victor Stinner b55cf2c2d8
[3.11] gh-104690: thread_run() checks for tstate dangling pointer (#109056) (#109134)
gh-104690: thread_run() checks for tstate dangling pointer (#109056)

thread_run() of _threadmodule.c now calls
_PyThreadState_CheckConsistency() to check if tstate is a dangling
pointer when Python is built in debug mode.

Rename ceval_gil.c is_tstate_valid() to
_PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.

(cherry picked from commit f63d37877a)
2023-09-08 11:10:33 +00:00
Gregory P. Smith 6ba1234c1c
[3.11] gh-104372: Drop the GIL around the vfork() call. (#104782) (#104958)
gh-104372: Drop the GIL around the vfork() call. (#104782)

On Linux where the `subprocess` module can use the `vfork` syscall for
faster spawning, prevent the parent process from blocking other threads
by dropping the GIL while it waits for the vfork'ed child process `exec`
outcome.  This prevents spawning a binary from a slow filesystem from
blocking the rest of the application.

Fixes #104372.

(cherry picked from commit d08679212d)
2023-09-01 08:53:06 +00:00
Erlend E. Aasland d79216d48f
[3.11] gh-107801: Improve the accuracy of io.IOBase.seek docs (#108268) (#108656)
(cherry picked from commit 8178a88bd8)

- Add param docstrings
- Link to os.SEEK_* constants
- Mention the return value in the initial paragraph

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-08-29 19:57:49 +00:00
Erlend E. Aasland bd951cd95b
[3.11] gh-107801: Document io.TextIOWrapper.tell (#108265) (#108548)
(cherry picked from commit 38afa4af9b)
2023-08-27 21:22:43 +00:00
Serhiy Storchaka b9fc536399
[3.11] gh-107913: Fix possible losses of OSError error codes (GH-107930) (GH-108524)
Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be
called immediately after using the C API which sets errno or the Windows
error code.
(cherry picked from commit 2b15536fa9)
2023-08-27 12:18:58 +00:00
Łukasz Langa c3d129f07e
[3.11] Revert "gh-46376: Return existing pointer when possible in ctypes (GH-107131) (GH-107488)" (#108412)
This reverts commit 57f27e4441.

The fix caused gh-107940. Until we have a bulletproof fix for that, the 3.11 backport needs to be reverted to make way for 3.11.5.
2023-08-24 13:26:19 +02:00
Hugo van Kemenade d678ee7719
[3.11] Trim trailing whitespace and test on CI (GH-104275) (#108215) 2023-08-22 12:57:31 +03:00
Miss Islington (bot) dd0a1f9da2
[3.11] gh-102507 Remove invisible pagebreak characters (GH-102531) (#108266)
gh-102507 Remove invisible pagebreak characters (GH-102531)
(cherry picked from commit b097925858)

Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com>
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2023-08-22 08:49:35 +00:00
Erlend E. Aasland cc42182c97
[3.11] gh-107801: Improve the accuracy of io.TextIOWrapper.seek docs (#107933) (#108264)
(cherry picked from commit 7f87ebbc3f)

Clearly document the supported seek() operations:

- Rewind to the start of the stream
- Restore a previous stream position (given by tell())
- Fast-forward to the end of the stream
2023-08-22 08:19:56 +00:00
Erlend E. Aasland e0ca3424ad
[3.11] gh-107801: Improve the accuracy of os.lseek docs (#107935) (#108137)
- name the last parameter *whence*, like it is for seek() methods on
  file objects
- add param docstrings
- structure the valid *whence* params

(cherry picked from commit dd4442c8f5)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-08-19 13:06:36 +00:00
Serhiy Storchaka 26137e2cf7
[3.11] gh-100061: Proper fix of the bug in the matching of possessive quantifiers (GH-102612) (GH-108004)
Restore the global Input Stream pointer after trying to match a sub-pattern.

Co-authored-by: Ma Lin <animalize@users.noreply.github.com>

(cherry picked from commit abd9cc52d9)
    
Co-authored-by: SKO <41810398+uyw4687@users.noreply.github.com>
2023-08-16 08:36:36 +00:00
Steve Dower ccf81e1088
[3.11] gh-106242: Fix path truncation in os.path.normpath (GH-106816) (#107982)
Co-authored-by: Finn Womack <flan313@gmail.com>
2023-08-15 19:07:52 +02:00
Serhiy Storchaka ec254c5dfa
[3.11] gh-106844: Fix issues in _winapi.LCMapStringEx (GH-107832) (GH-107875)
* Strings with length from 2**31-1 to 2**32-2 always caused MemoryError,
   it doesn't matter how much memory is available.
* Strings with length exactly 2**32-1 caused OSError.
* Strings longer than 2**32-1 characters were truncated due to integer overflow bug.

Now strings longer than 2**31-1 characters caused OverflowError.
(cherry picked from commit 04cc01453d)
2023-08-12 14:06:56 +03:00
Serhiy Storchaka 22b39d13ec
[3.11] gh-107735: Add C API tests for PySys_GetObject() and PySys_SetObject() (GH-107736) (GH-107741)
(cherry picked from commit bea5f93196)
2023-08-07 20:51:00 +00:00
Miss Islington (bot) 4f65f03f2d
[3.11] gh-107077: Raise SSLCertVerificationError even if the error is set via SSL_ERROR_SYSCALL (GH-107586) (#107588)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
2023-08-03 15:09:27 +01:00
Charlie Zhao a15d06c230
[3.11] gh-106263: Fix segfault in `signaldict_repr` in `_decimal` module (#… (#107490)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
(cherry picked from commit 3979150a0d)
2023-07-31 15:52:23 +02:00
Łukasz Langa 57f27e4441
[3.11] gh-46376: Return existing pointer when possible in ctypes (GH-107131) (#107488)
(cherry picked from commit 08447b5deb)

Co-authored-by: Konstantin <kpp.live+github@gmail.com>
2023-07-31 11:16:59 +02:00
justdan6 4049c5d6f8
[3.11] gh-106881: Check for linux/limits.h before including it (#107397) (#107415)
* [3.11] gh-106881: Check for linux/limits.h before including it (#107397)

* Check for linux/limits.h before including it

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
(cherry picked from commit 11c055f5ff)

* Fix sphinx-lint error in NEWS entry
2023-07-28 23:36:54 +00:00
Miss Islington (bot) c7d9976094
[3.11] gh-104432: Use `memcpy()` to avoid misaligned loads (GH-104433) (#107356)
gh-104432: Use `memcpy()` to avoid misaligned loads (GH-104433)

Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
(cherry picked from commit f01e4cedba)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
2023-07-28 06:36:45 +00:00
Miss Islington (bot) 36208b5f6a
[3.11] gh-106350: Tkinter: do not ignore return value of `mp_init()` (GH-106351) (GH-107259)
(cherry picked from commit b5ae7c4984)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
2023-07-26 10:58:07 +03:00
Serhiy Storchaka b8b3e6afc0
[3.11] gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613) (GH-107224)
Previously *consumed was not set in this case.
(cherry picked from commit f08e52ccb0)
2023-07-25 14:15:14 +03:00
Serhiy Storchaka fced79f91e
[3.11] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855) (GH-106863)
[3.11] [3.12] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855)

Fix _ssl, _stat, _testinternalcapi, _threadmodule, cmath, math, posix, time.
(cherry picked from commit 3e65baee72).
(cherry picked from commit a423ddbdea)
2023-07-19 09:40:38 +03:00
Serhiy Storchaka 3841af49e5
[3.11] gh-86493: Fix possible leaks in modules initialization: _curses_panel, _decimal, posix, xxsubtype (GH-106767) (GH-106849) (GH-106851)
(cherry picked from commit 745492355b)
(cherry picked from commit 970cb8eaba)
2023-07-18 12:53:17 +03:00
Miss Islington (bot) a782d51913
[3.11] gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (GH-106832) (#106836)
gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (GH-106832)
(cherry picked from commit ebf2c56b33)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-07-17 20:31:10 +00:00
Dennis Sweeney d488970ae6
[3.11] gh-105235: Prevent reading outside buffer during mmap.find() (… (#106710)
[3.11] gh-105235: Prevent reading outside buffer during mmap.find() (GH-105252)

* Add a special case for s[-m:] == p in _PyBytes_Find

* Add tests for _PyBytes_Find

* Make sure that start <= end in mmap.find.
(cherry picked from commit ab86426a34)
2023-07-14 22:17:09 -04:00
Serhiy Storchaka dbe416b82b
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and Py… (#106040)
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr (GH-106034)

These functions are broken by design because they discard any exceptions raised
inside, including MemoryError and KeyboardInterrupt.  They should not be
used in new code..
(cherry picked from commit 1d33d53780)
2023-06-24 16:41:02 -07:00
Erlend E. Aasland 2b1745f37c
[3.11] gh-105375: Improve error handling in _Unpickler_SetInputStream() (#105667) (#105721)
Prevent exceptions from possibly being overwritten in case of multiple
failures.

(cherry picked from commit 217589d4f3)
2023-06-13 09:07:20 +00:00
Erlend E. Aasland 36c393c044
[3.11] gh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (#105686) (#105711)
* [3.11] gh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (#105686)

All fields must be explicitly initialised to prevent manipulation of
uninitialised fields in dealloc.

Align initialisation order with the layout of the object structs.

(cherry picked from commit ca3cc4b95d)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-13 06:50:00 +00:00
Miss Islington (bot) 261d0b4f0e
[3.11] gh-105436: The environment block should end with two null wchar_t values (GH-105495) (#105701)
gh-105436: The environment block should end with two null wchar_t values (GH-105495)
(cherry picked from commit 4f7d3b602d)

Co-authored-by: Dora203 <66343334+sku2000@users.noreply.github.com>
2023-06-12 16:49:57 +00:00
Erlend E. Aasland e5fe017143
[3.11] gh-105375: Harden pyexpat initialisation (#105606) (#105668)
(cherry picked from commit 20a56d8bec)

Add proper error handling to add_errors_module() to prevent exceptions
from possibly being overwritten.
2023-06-11 21:28:12 +00:00
Miss Islington (bot) a03449374e
[3.11] gh-105375: Improve error handling in _ctypes (GH-105593) (#105664)
Prevent repeated PyLong_FromVoidPtr() from possibly overwriting the
current exception.
(cherry picked from commit e8998e46a7)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-11 20:30:47 +00:00
Erlend E. Aasland 87e493b11a
[3.11] gh-105375: Harden _ssl initialisation (#105599) (#105651)
(cherry picked from commit 01f4230460)

Add proper error handling to prevent reference leaks and overwritten
exceptions.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-11 21:25:36 +02:00
Miss Islington (bot) cb26fafdcc
[3.11] gh-105375: Improve _decimal error handling (GH-105605) (#105648)
Fix a bug where an exception could end up being overwritten.
(cherry picked from commit c932f72849)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-11 10:58:56 +00:00
Miss Islington (bot) cfa0f7c59b
[3.11] gh-105375: Harden _datetime initialisation (GH-105604) (#105646)
Improve error handling so init bails on the first exception.
(cherry picked from commit 16d49680b5)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-11 10:41:37 +00:00
Miss Islington (bot) 3c08e54ccf
[3.11] gh-105375: Improve array.array exception handling (GH-105594) (#105643)
Fix a bug where 'tp_richcompare' could end up overwriting an exception.
(cherry picked from commit 35cff545db)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-11 10:22:31 +00:00
Miss Islington (bot) 4ceb5c4924
[3.11] gh-105375: Improve error handling in `zoneinfo` module (GH-105586) (#105613)
Fix bugs where exceptions could end up being overwritten
because of deferred error handling.

(cherry picked from commit 33c92c4f15)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-09 22:54:00 +00:00
Miss Islington (bot) e4748628e1
[3.11] gh-105375: Improve error handling in _elementtree (GH-105591) (#105601)
Fix bugs where exceptions could end up being overwritten.
(cherry picked from commit 00b599ab5a)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-09 21:19:59 +00:00
Miss Islington (bot) c1797f661d
[3.11] gh-105375: Improve posix error handling (GH-105592) (#105597)
Fix a bug where an IndexError could end up being overwritten.
(cherry picked from commit f668f73bc8)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-09 20:55:34 +00:00