Skip to content

Commit 2919821

Browse files
ttaylorrdscho
andcommitted
t1300: demonstrate failure when renaming sections with long lines
When renaming a configuration section which has an entry whose length exceeds the size of our buffer in config.c's implementation of `git_config_copy_or_rename_section_in_file()`, Git will incorrectly form a new configuration section with part of the data in the section being removed. In this instance, our first configuration file looks something like: [b] c = d <spaces> [a] e = f [a] g = h Here, we have two configuration values, "b.c", and "a.g". The value "[a] e = f" belongs to the configuration value "b.c", and does not form its own section. However, when renaming the section 'a' to 'xyz', Git will write back "[xyz]\ne = f", but "[xyz]" is still attached to the value of "b.c", which is why "e = f" on its own line becomes a new entry called "b.e". A slightly different example embeds the section being renamed within another section. Demonstrate this failure in a test in t1300, which we will fix in the following commit. Co-authored-by: Johannes Schindelin <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 2f3b28f commit 2919821

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

t/t1300-config.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,26 @@ test_expect_success 'renaming to bogus section is rejected' '
613613
test_must_fail git config --rename-section branch.zwei "bogus name"
614614
'
615615

616+
test_expect_failure 'renaming a section with a long line' '
617+
{
618+
printf "[b]\\n" &&
619+
printf " c = d %1024s [a] e = f\\n" " " &&
620+
printf "[a] g = h\\n"
621+
} >y &&
622+
git config -f y --rename-section a xyz &&
623+
test_must_fail git config -f y b.e
624+
'
625+
626+
test_expect_failure 'renaming an embedded section with a long line' '
627+
{
628+
printf "[b]\\n" &&
629+
printf " c = d %1024s [a] [foo] e = f\\n" " " &&
630+
printf "[a] g = h\\n"
631+
} >y &&
632+
git config -f y --rename-section a xyz &&
633+
test_must_fail git config -f y foo.e
634+
'
635+
616636
cat >> .git/config << EOF
617637
[branch "zwei"] a = 1 [branch "vier"]
618638
EOF

0 commit comments

Comments
 (0)