Commit 11a2482
authored
gh-151416: fix a borrowed ref potential use after free via fspath in os.spawnv/spawnve (GH-151417)
* gh-151416: Fix use-after-free in os.spawnv/spawnve when __fspath__ mutates argv
The argv conversion loops passed references borrowed from the argv list
into fsconvert_strdup(). An item's __fspath__() can mutate the list and
release its reference to the item, leaving the converter operating on a
freed object. A shrunk list could also make PyList_GetItem() return
NULL, which PyUnicode_FS{Converter,Decoder}() treat as a request to
release an uninitialized output variable.
Hold a strong reference to each item across the conversion, matching
parse_arglist() and parse_envlist().
* gh-151416: Don't mask non-TypeError argv conversion errors in os.spawnv
os.spawnv() replaced any error raised during argv item conversion,
such as MemoryError, codec errors, or the embedded-null ValueError,
with a generic TypeError. Only add the contextual message when the
conversion actually raised TypeError, matching how os.spawnve() and
the exec functions propagate these errors.
The test is gated to the native C spawnv: the Python fallback used
elsewhere reports conversion failures from the forked child as exit
status 127 instead of raising.
(cherry picked from commit f57d3d6)
1 parent 84badb7 commit 11a2482
3 files changed
Lines changed: 65 additions & 14 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
101 | 110 | | |
102 | 111 | | |
103 | 112 | | |
| |||
3762 | 3771 | | |
3763 | 3772 | | |
3764 | 3773 | | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
3765 | 3793 | | |
3766 | 3794 | | |
3767 | 3795 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7729 | 7729 | | |
7730 | 7730 | | |
7731 | 7731 | | |
7732 | | - | |
7733 | 7732 | | |
7734 | 7733 | | |
7735 | 7734 | | |
7736 | 7735 | | |
7737 | 7736 | | |
7738 | 7737 | | |
7739 | | - | |
7740 | 7738 | | |
7741 | 7739 | | |
7742 | 7740 | | |
7743 | | - | |
7744 | 7741 | | |
7745 | 7742 | | |
7746 | 7743 | | |
| |||
7758 | 7755 | | |
7759 | 7756 | | |
7760 | 7757 | | |
7761 | | - | |
7762 | | - | |
| 7758 | + | |
| 7759 | + | |
| 7760 | + | |
| 7761 | + | |
| 7762 | + | |
| 7763 | + | |
7763 | 7764 | | |
7764 | | - | |
7765 | | - | |
7766 | | - | |
7767 | 7765 | | |
7768 | 7766 | | |
| 7767 | + | |
| 7768 | + | |
| 7769 | + | |
| 7770 | + | |
| 7771 | + | |
| 7772 | + | |
| 7773 | + | |
| 7774 | + | |
| 7775 | + | |
| 7776 | + | |
| 7777 | + | |
| 7778 | + | |
| 7779 | + | |
| 7780 | + | |
7769 | 7781 | | |
7770 | 7782 | | |
7771 | 7783 | | |
| |||
7836 | 7848 | | |
7837 | 7849 | | |
7838 | 7850 | | |
7839 | | - | |
7840 | 7851 | | |
7841 | 7852 | | |
7842 | 7853 | | |
| |||
7845 | 7856 | | |
7846 | 7857 | | |
7847 | 7858 | | |
7848 | | - | |
7849 | 7859 | | |
7850 | 7860 | | |
7851 | 7861 | | |
7852 | | - | |
7853 | 7862 | | |
7854 | 7863 | | |
7855 | 7864 | | |
| |||
7873 | 7882 | | |
7874 | 7883 | | |
7875 | 7884 | | |
7876 | | - | |
7877 | | - | |
7878 | | - | |
| 7885 | + | |
| 7886 | + | |
| 7887 | + | |
| 7888 | + | |
| 7889 | + | |
| 7890 | + | |
7879 | 7891 | | |
7880 | 7892 | | |
7881 | 7893 | | |
| 7894 | + | |
| 7895 | + | |
| 7896 | + | |
| 7897 | + | |
| 7898 | + | |
| 7899 | + | |
7882 | 7900 | | |
7883 | 7901 | | |
7884 | 7902 | | |
| |||
0 commit comments