-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143988: tation crashes in socket sendmsg/recvmsg_into via __buffer__
#143987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tonghuaroot
wants to merge
5
commits into
python:main
Choose a base branch
from
tonghuaroot:fix-socket-reentrant-mutation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+75
−10
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c8aad6
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_…
tonghuaroot e0f92e6
Simplify NEWS entry: use 'concurrently' instead of 're-entrantly'
tonghuaroot 12c8272
Simplify MutBuffer in recvmsg_into test: remove self._data
tonghuaroot b578feb
Remove unnecessary comments and try/except - calls succeed after fix
tonghuaroot df46bde
Merge branch 'main' into fix-socket-reentrant-mutation
tonghuaroot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Security/2026-01-18-06-42-47.gh-issue-143988.MtLtCP.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fixed crashes in :meth:`socket.socket.sendmsg` and :meth:`socket.socket.recvmsg_into` | ||
| that could occur if buffer sequences are concurrently mutated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4527,11 +4527,13 @@ sock_recvmsg_into(PyObject *self, PyObject *args) | |
| &buffers_arg, &ancbufsize, &flags)) | ||
| return NULL; | ||
|
|
||
| if ((fast = PySequence_Fast(buffers_arg, | ||
| "recvmsg_into() argument 1 must be an " | ||
| "iterable")) == NULL) | ||
| fast = PySequence_Tuple(buffers_arg); | ||
| if (fast == NULL) { | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "recvmsg_into() argument 1 must be an iterable"); | ||
| return NULL; | ||
| nitems = PySequence_Fast_GET_SIZE(fast); | ||
| } | ||
| nitems = PyTuple_GET_SIZE(fast); | ||
| if (nitems > INT_MAX) { | ||
| PyErr_SetString(PyExc_OSError, "recvmsg_into() argument 1 is too long"); | ||
| goto finally; | ||
|
|
@@ -4545,7 +4547,7 @@ sock_recvmsg_into(PyObject *self, PyObject *args) | |
| goto finally; | ||
| } | ||
| for (; nbufs < nitems; nbufs++) { | ||
| if (!PyArg_Parse(PySequence_Fast_GET_ITEM(fast, nbufs), | ||
| if (!PyArg_Parse(PyTuple_GET_ITEM(fast, nbufs), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit confused with this one. There is nothing that checks for the fact that this really a buffer object or did I forget about PyArg_Parse? |
||
| "w*;recvmsg_into() argument 1 must be an iterable " | ||
| "of single-segment read-write buffers", | ||
| &bufs[nbufs])) | ||
|
|
@@ -4854,14 +4856,14 @@ sock_sendmsg_iovec(PySocketSockObject *s, PyObject *data_arg, | |
|
|
||
| /* Fill in an iovec for each message part, and save the Py_buffer | ||
| structs to release afterwards. */ | ||
| data_fast = PySequence_Fast(data_arg, | ||
| "sendmsg() argument 1 must be an " | ||
| "iterable"); | ||
| data_fast = PySequence_Tuple(data_arg); | ||
| if (data_fast == NULL) { | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "sendmsg() argument 1 must be an iterable"); | ||
| goto finally; | ||
| } | ||
|
|
||
| ndataparts = PySequence_Fast_GET_SIZE(data_fast); | ||
| ndataparts = PyTuple_GET_SIZE(data_fast); | ||
| if (ndataparts > INT_MAX) { | ||
| PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long"); | ||
| goto finally; | ||
|
|
@@ -4883,7 +4885,7 @@ sock_sendmsg_iovec(PySocketSockObject *s, PyObject *data_arg, | |
| } | ||
| } | ||
| for (; ndatabufs < ndataparts; ndatabufs++) { | ||
| if (PyObject_GetBuffer(PySequence_Fast_GET_ITEM(data_fast, ndatabufs), | ||
| if (PyObject_GetBuffer(PyTuple_GET_ITEM(data_fast, ndatabufs), | ||
| &databufs[ndatabufs], PyBUF_SIMPLE) < 0) | ||
| goto finally; | ||
| iovs[ndatabufs].iov_base = databufs[ndatabufs].buf; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a refwrence to the gh issue as well. Using plain comments and
"See: URL TO THE ISSUE."
And not just gh-XXXXXX. URLs can be opened directly from IDEs, but not gh-* objects.