Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
597c672
socket: fix re-entrant mutation in sendmsg ancillary data
priyanshu2282-cyber Jan 15, 2026
7e57097
test_socket: add regression test for sendmsg re-entrancy
priyanshu2282-cyber Jan 15, 2026
a6fbd4b
gh-143637: Fix reentrant mutation crash in socket.sendmsg
priyanshu2282-cyber Jan 15, 2026
be7371d
chore: rerun CI
priyanshu2282-cyber Jan 16, 2026
4703c2b
restore spacing style for controllen calculation
priyanshu2282-cyber Jan 17, 2026
2bd7e14
📜🤖 Added by blurb_it.
blurb-it[bot] Jan 17, 2026
710daaa
add public wrapper for sendmsg re-entrant ancillary mutation test
priyanshu2282-cyber Jan 17, 2026
a2992a8
Merge branch 'fix-sendmsg-reentrant-cmsg' of https://github.com/priya…
priyanshu2282-cyber Jan 17, 2026
75d8ae9
fixed trailing whitespace
priyanshu2282-cyber Jan 17, 2026
6f0ddf4
PySequence_Tuple instead of PySequence_Fast and removed INCREF, DECREF
priyanshu2282-cyber Jan 17, 2026
ff8af98
Fix trailing whitespace
priyanshu2282-cyber Jan 17, 2026
5f0a05a
Fix sendmsg re-entrant ancillary mutation crash
priyanshu2282-cyber Jan 19, 2026
082e6b7
Corrected Indentation and moved test to seperate class
priyanshu2282-cyber Jan 19, 2026
fb99129
Update Modules/socketmodule.c
priyanshu2282-cyber Jan 19, 2026
7ec2dd6
Update Modules/socketmodule.c
priyanshu2282-cyber Jan 20, 2026
57b33f1
Move test to GeneralModuleTests
priyanshu2282-cyber Jan 20, 2026
3587510
Test added at last
priyanshu2282-cyber Jan 21, 2026
ef61722
Fixed trailing whitespace
priyanshu2282-cyber Jan 21, 2026
b299085
Update Lib/test/test_socket.py
priyanshu2282-cyber Jan 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,29 @@ def test_addressinfo_enum(self):
source=_socket)
enum._test_simple_enum(CheckedAddressInfo, socket.AddressInfo)

@unittest.skipUnless(hasattr(socket.socket, "sendmsg"),"sendmsg not supported")
def test_sendmsg_reentrant_ancillary_mutation(self):

class Mut:
def __index__(self):
seq.clear()
return 0

seq = [
(socket.SOL_SOCKET, Mut(), b'x'),
(socket.SOL_SOCKET, 0, b'x'),
]

left, right = socket.socketpair()
self.addCleanup(left.close)
self.addCleanup(right.close)
self.assertRaises(
OSError,
left.sendmsg,
[b'x'],
seq,
)


@unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.')
class BasicCANTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a crash in socket.sendmsg() that could occur if ancillary data is mutated re-entrantly during argument parsing.
13 changes: 8 additions & 5 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4977,11 +4977,13 @@ _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg,
if (cmsg_arg == NULL)
ncmsgs = 0;
else {
if ((cmsg_fast = PySequence_Fast(cmsg_arg,
"sendmsg() argument 2 must be an "
"iterable")) == NULL)
cmsg_fast = PySequence_Tuple(cmsg_arg);
if (cmsg_fast == NULL) {
PyErr_SetString(PyExc_TypeError,
"sendmsg() argument 2 must be an iterable");
goto finally;
ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast);
}
ncmsgs = PyTuple_GET_SIZE(cmsg_fast);
}

#ifndef CMSG_SPACE
Expand All @@ -5001,8 +5003,9 @@ _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg,
controllen = controllen_last = 0;
while (ncmsgbufs < ncmsgs) {
size_t bufsize, space;
PyObject *item = PyTuple_GET_ITEM(cmsg_fast, ncmsgbufs);

if (!PyArg_Parse(PySequence_Fast_GET_ITEM(cmsg_fast, ncmsgbufs),
if (!PyArg_Parse(item,
"(iiy*):[sendmsg() ancillary data items]",
&cmsgs[ncmsgbufs].level,
&cmsgs[ncmsgbufs].type,
Expand Down
Loading