Commit 896f7fd
authored
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.
Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
1 parent a621e8a commit 896f7fd
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 | |
|---|---|---|---|
| |||
7529 | 7529 | | |
7530 | 7530 | | |
7531 | 7531 | | |
| 7532 | + | |
| 7533 | + | |
| 7534 | + | |
| 7535 | + | |
| 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 | + | |
7532 | 7588 | | |
7533 | 7589 | | |
7534 | 7590 | | |
| |||
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 | |
|---|---|---|---|
| |||
4526 | 4526 | | |
4527 | 4527 | | |
4528 | 4528 | | |
4529 | | - | |
| 4529 | + | |
4530 | 4530 | | |
4531 | 4531 | | |
4532 | 4532 | | |
4533 | 4533 | | |
4534 | 4534 | | |
4535 | | - | |
4536 | | - | |
4537 | | - | |
| 4535 | + | |
| 4536 | + | |
| 4537 | + | |
| 4538 | + | |
4538 | 4539 | | |
4539 | | - | |
| 4540 | + | |
| 4541 | + | |
4540 | 4542 | | |
4541 | 4543 | | |
4542 | 4544 | | |
| |||
4550 | 4552 | | |
4551 | 4553 | | |
4552 | 4554 | | |
4553 | | - | |
| 4555 | + | |
4554 | 4556 | | |
4555 | 4557 | | |
4556 | 4558 | | |
| |||
4566 | 4568 | | |
4567 | 4569 | | |
4568 | 4570 | | |
4569 | | - | |
| 4571 | + | |
4570 | 4572 | | |
4571 | 4573 | | |
4572 | 4574 | | |
| |||
4861 | 4863 | | |
4862 | 4864 | | |
4863 | 4865 | | |
4864 | | - | |
4865 | | - | |
4866 | | - | |
| 4866 | + | |
4867 | 4867 | | |
| 4868 | + | |
| 4869 | + | |
4868 | 4870 | | |
4869 | 4871 | | |
4870 | 4872 | | |
4871 | | - | |
| 4873 | + | |
4872 | 4874 | | |
4873 | 4875 | | |
4874 | 4876 | | |
| |||
4890 | 4892 | | |
4891 | 4893 | | |
4892 | 4894 | | |
4893 | | - | |
| 4895 | + | |
4894 | 4896 | | |
4895 | 4897 | | |
4896 | 4898 | | |
| |||
0 commit comments