Commit 632daaf
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)
Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
1 parent 4ef6a37 commit 632daaf
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 | |
|---|---|---|---|
| |||
7449 | 7449 | | |
7450 | 7450 | | |
7451 | 7451 | | |
| 7452 | + | |
| 7453 | + | |
| 7454 | + | |
| 7455 | + | |
| 7456 | + | |
| 7457 | + | |
| 7458 | + | |
| 7459 | + | |
| 7460 | + | |
| 7461 | + | |
| 7462 | + | |
| 7463 | + | |
| 7464 | + | |
| 7465 | + | |
| 7466 | + | |
| 7467 | + | |
| 7468 | + | |
| 7469 | + | |
| 7470 | + | |
| 7471 | + | |
| 7472 | + | |
| 7473 | + | |
| 7474 | + | |
| 7475 | + | |
| 7476 | + | |
| 7477 | + | |
| 7478 | + | |
| 7479 | + | |
| 7480 | + | |
| 7481 | + | |
| 7482 | + | |
| 7483 | + | |
| 7484 | + | |
| 7485 | + | |
| 7486 | + | |
| 7487 | + | |
| 7488 | + | |
| 7489 | + | |
| 7490 | + | |
| 7491 | + | |
| 7492 | + | |
| 7493 | + | |
| 7494 | + | |
| 7495 | + | |
| 7496 | + | |
| 7497 | + | |
| 7498 | + | |
| 7499 | + | |
| 7500 | + | |
| 7501 | + | |
| 7502 | + | |
| 7503 | + | |
| 7504 | + | |
| 7505 | + | |
| 7506 | + | |
| 7507 | + | |
7452 | 7508 | | |
7453 | 7509 | | |
7454 | 7510 | | |
| |||
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 | |
|---|---|---|---|
| |||
4497 | 4497 | | |
4498 | 4498 | | |
4499 | 4499 | | |
4500 | | - | |
| 4500 | + | |
4501 | 4501 | | |
4502 | 4502 | | |
4503 | 4503 | | |
4504 | 4504 | | |
4505 | 4505 | | |
4506 | | - | |
4507 | | - | |
4508 | | - | |
| 4506 | + | |
| 4507 | + | |
| 4508 | + | |
| 4509 | + | |
4509 | 4510 | | |
4510 | | - | |
| 4511 | + | |
| 4512 | + | |
4511 | 4513 | | |
4512 | 4514 | | |
4513 | 4515 | | |
| |||
4521 | 4523 | | |
4522 | 4524 | | |
4523 | 4525 | | |
4524 | | - | |
| 4526 | + | |
4525 | 4527 | | |
4526 | 4528 | | |
4527 | 4529 | | |
| |||
4537 | 4539 | | |
4538 | 4540 | | |
4539 | 4541 | | |
4540 | | - | |
| 4542 | + | |
4541 | 4543 | | |
4542 | 4544 | | |
4543 | 4545 | | |
| |||
4836 | 4838 | | |
4837 | 4839 | | |
4838 | 4840 | | |
4839 | | - | |
4840 | | - | |
4841 | | - | |
| 4841 | + | |
4842 | 4842 | | |
| 4843 | + | |
| 4844 | + | |
4843 | 4845 | | |
4844 | 4846 | | |
4845 | 4847 | | |
4846 | | - | |
| 4848 | + | |
4847 | 4849 | | |
4848 | 4850 | | |
4849 | 4851 | | |
| |||
4865 | 4867 | | |
4866 | 4868 | | |
4867 | 4869 | | |
4868 | | - | |
| 4870 | + | |
4869 | 4871 | | |
4870 | 4872 | | |
4871 | 4873 | | |
| |||
0 commit comments