Commit 5453842
Validate config key section names before writing
GitConfigParser already rejected CR, LF, and NUL in config values before
writing, but section and option names could still reach configparser. Because
GitPython writes section headers itself, a newline-bearing section name could
split the output into additional headers.
Reject CR, LF, and NUL in section and option names on write paths that create
or set config keys: add_section(), set(), set_value(), add_value(), and
rename_section() destinations. This matches Git config key validation behavior;
Git source commit 94f057755b7941b321fd11fec1b2e3ca5313a4e0 reports invalid keys
containing newlines from config.c, and local git 2.50.1 rejects newline-bearing
config keys.
Add a regression test covering unsafe section and option names while preserving
safe writes.
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>1 parent b7f5fde commit 5453842
2 files changed
Lines changed: 47 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
778 | 781 | | |
779 | 782 | | |
780 | 783 | | |
| 784 | + | |
781 | 785 | | |
782 | 786 | | |
783 | 787 | | |
| |||
884 | 888 | | |
885 | 889 | | |
886 | 890 | | |
887 | | - | |
| 891 | + | |
888 | 892 | | |
889 | 893 | | |
890 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
891 | 899 | | |
892 | 900 | | |
893 | 901 | | |
| |||
896 | 904 | | |
897 | 905 | | |
898 | 906 | | |
| 907 | + | |
| 908 | + | |
899 | 909 | | |
900 | 910 | | |
901 | 911 | | |
| |||
920 | 930 | | |
921 | 931 | | |
922 | 932 | | |
| 933 | + | |
| 934 | + | |
923 | 935 | | |
924 | 936 | | |
925 | 937 | | |
| |||
948 | 960 | | |
949 | 961 | | |
950 | 962 | | |
| 963 | + | |
| 964 | + | |
951 | 965 | | |
952 | 966 | | |
953 | 967 | | |
| |||
968 | 982 | | |
969 | 983 | | |
970 | 984 | | |
| 985 | + | |
971 | 986 | | |
972 | 987 | | |
973 | 988 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
166 | 197 | | |
167 | 198 | | |
168 | 199 | | |
| |||
0 commit comments