Commit 87b9729
[3.14] gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (#143987) (#151251)
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (#143987)
Fix crashes in socket.sendmsg() and socket.recvmsg_into() that could
occur if buffer sequences are mutated re-entrantly during argument
parsing via __buffer__ protocol callbacks.
The bug occurs because:
1. PySequence_Fast() returns the original list object when the input
is already a list (not a copy).
2. During iteration, PyObject_GetBuffer() triggers __buffer__
callbacks which may clear the list.
3. Subsequent iterations access invalid memory (heap OOB read).
The fix replaces PySequence_Fast() with PySequence_Tuple() which
always creates a new tuple, ensuring the sequence cannot be mutated
during iteration.
(cherry picked from commit 896f7fd)
(cherry picked from commit 632daaf)
Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
1 parent a1f43ef commit 87b9729
3 files changed
Lines changed: 72 additions & 12 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7284 | 7284 | | |
7285 | 7285 | | |
7286 | 7286 | | |
| 7287 | + | |
| 7288 | + | |
| 7289 | + | |
| 7290 | + | |
| 7291 | + | |
| 7292 | + | |
| 7293 | + | |
| 7294 | + | |
| 7295 | + | |
| 7296 | + | |
| 7297 | + | |
| 7298 | + | |
| 7299 | + | |
| 7300 | + | |
| 7301 | + | |
| 7302 | + | |
| 7303 | + | |
| 7304 | + | |
| 7305 | + | |
| 7306 | + | |
| 7307 | + | |
| 7308 | + | |
| 7309 | + | |
| 7310 | + | |
| 7311 | + | |
| 7312 | + | |
| 7313 | + | |
| 7314 | + | |
| 7315 | + | |
| 7316 | + | |
| 7317 | + | |
| 7318 | + | |
| 7319 | + | |
| 7320 | + | |
| 7321 | + | |
| 7322 | + | |
| 7323 | + | |
| 7324 | + | |
| 7325 | + | |
| 7326 | + | |
| 7327 | + | |
| 7328 | + | |
| 7329 | + | |
| 7330 | + | |
| 7331 | + | |
| 7332 | + | |
| 7333 | + | |
| 7334 | + | |
| 7335 | + | |
| 7336 | + | |
| 7337 | + | |
| 7338 | + | |
| 7339 | + | |
| 7340 | + | |
| 7341 | + | |
| 7342 | + | |
7287 | 7343 | | |
7288 | 7344 | | |
7289 | 7345 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4296 | 4296 | | |
4297 | 4297 | | |
4298 | 4298 | | |
4299 | | - | |
| 4299 | + | |
4300 | 4300 | | |
4301 | 4301 | | |
4302 | 4302 | | |
4303 | 4303 | | |
4304 | 4304 | | |
4305 | | - | |
4306 | | - | |
4307 | | - | |
| 4305 | + | |
| 4306 | + | |
| 4307 | + | |
| 4308 | + | |
4308 | 4309 | | |
4309 | | - | |
| 4310 | + | |
| 4311 | + | |
4310 | 4312 | | |
4311 | 4313 | | |
4312 | 4314 | | |
| |||
4320 | 4322 | | |
4321 | 4323 | | |
4322 | 4324 | | |
4323 | | - | |
| 4325 | + | |
4324 | 4326 | | |
4325 | 4327 | | |
4326 | 4328 | | |
| |||
4336 | 4338 | | |
4337 | 4339 | | |
4338 | 4340 | | |
4339 | | - | |
| 4341 | + | |
4340 | 4342 | | |
4341 | 4343 | | |
4342 | 4344 | | |
| |||
4629 | 4631 | | |
4630 | 4632 | | |
4631 | 4633 | | |
4632 | | - | |
4633 | | - | |
4634 | | - | |
| 4634 | + | |
4635 | 4635 | | |
| 4636 | + | |
| 4637 | + | |
4636 | 4638 | | |
4637 | 4639 | | |
4638 | 4640 | | |
4639 | | - | |
| 4641 | + | |
4640 | 4642 | | |
4641 | 4643 | | |
4642 | 4644 | | |
| |||
4658 | 4660 | | |
4659 | 4661 | | |
4660 | 4662 | | |
4661 | | - | |
| 4663 | + | |
4662 | 4664 | | |
4663 | 4665 | | |
4664 | 4666 | | |
| |||
0 commit comments