Commit 9261f8b
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (GH-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 637746d commit 9261f8b
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 | |
|---|---|---|---|
| |||
7534 | 7534 | | |
7535 | 7535 | | |
7536 | 7536 | | |
| 7537 | + | |
| 7538 | + | |
| 7539 | + | |
| 7540 | + | |
| 7541 | + | |
| 7542 | + | |
| 7543 | + | |
| 7544 | + | |
| 7545 | + | |
| 7546 | + | |
| 7547 | + | |
| 7548 | + | |
| 7549 | + | |
| 7550 | + | |
| 7551 | + | |
| 7552 | + | |
| 7553 | + | |
| 7554 | + | |
| 7555 | + | |
| 7556 | + | |
| 7557 | + | |
| 7558 | + | |
| 7559 | + | |
| 7560 | + | |
| 7561 | + | |
| 7562 | + | |
| 7563 | + | |
| 7564 | + | |
| 7565 | + | |
| 7566 | + | |
| 7567 | + | |
| 7568 | + | |
| 7569 | + | |
| 7570 | + | |
| 7571 | + | |
| 7572 | + | |
| 7573 | + | |
| 7574 | + | |
| 7575 | + | |
| 7576 | + | |
| 7577 | + | |
| 7578 | + | |
| 7579 | + | |
| 7580 | + | |
| 7581 | + | |
| 7582 | + | |
| 7583 | + | |
| 7584 | + | |
| 7585 | + | |
| 7586 | + | |
| 7587 | + | |
| 7588 | + | |
| 7589 | + | |
| 7590 | + | |
| 7591 | + | |
| 7592 | + | |
7537 | 7593 | | |
7538 | 7594 | | |
7539 | 7595 | | |
| |||
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 | |
|---|---|---|---|
| |||
4518 | 4518 | | |
4519 | 4519 | | |
4520 | 4520 | | |
4521 | | - | |
| 4521 | + | |
4522 | 4522 | | |
4523 | 4523 | | |
4524 | 4524 | | |
4525 | 4525 | | |
4526 | 4526 | | |
4527 | | - | |
4528 | | - | |
4529 | | - | |
| 4527 | + | |
| 4528 | + | |
| 4529 | + | |
| 4530 | + | |
4530 | 4531 | | |
4531 | | - | |
| 4532 | + | |
| 4533 | + | |
4532 | 4534 | | |
4533 | 4535 | | |
4534 | 4536 | | |
| |||
4542 | 4544 | | |
4543 | 4545 | | |
4544 | 4546 | | |
4545 | | - | |
| 4547 | + | |
4546 | 4548 | | |
4547 | 4549 | | |
4548 | 4550 | | |
| |||
4558 | 4560 | | |
4559 | 4561 | | |
4560 | 4562 | | |
4561 | | - | |
| 4563 | + | |
4562 | 4564 | | |
4563 | 4565 | | |
4564 | 4566 | | |
| |||
4853 | 4855 | | |
4854 | 4856 | | |
4855 | 4857 | | |
4856 | | - | |
4857 | | - | |
4858 | | - | |
| 4858 | + | |
4859 | 4859 | | |
| 4860 | + | |
| 4861 | + | |
4860 | 4862 | | |
4861 | 4863 | | |
4862 | 4864 | | |
4863 | | - | |
| 4865 | + | |
4864 | 4866 | | |
4865 | 4867 | | |
4866 | 4868 | | |
| |||
4882 | 4884 | | |
4883 | 4885 | | |
4884 | 4886 | | |
4885 | | - | |
| 4887 | + | |
4886 | 4888 | | |
4887 | 4889 | | |
4888 | 4890 | | |
| |||
0 commit comments