From 02e5ba4ae63729c28704280f1b8cfcb205c06960 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 1 Jan 2008 01:17:34 -0500 Subject: config: handle lack of newline at end of file better The config parsing routines use the static global 'config_file' to store the FILE* pointing to the current config file being parsed. The function get_next_char() automatically converts an EOF on this file to a newline for the convenience of its callers, and it sets config_file to NULL to indicate that EOF was reached. This throws away useful information, though, since some routines want to call ftell on 'config_file' to find out exactly _where_ the routine ended. In the case of a key ending at EOF boundary, we ended up segfaulting in some cases (changing that key or adding another key in its section), or failing to provide the necessary newline (adding a new section). This patch adds a new flag to indicate EOF and uses that instead of setting config_file to NULL. It also makes sure to add newlines where necessary for truncated input. All three included tests fail without the patch. Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 t/t1303-wacky-config.sh (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh new file mode 100755 index 0000000000..99985dcd79 --- /dev/null +++ b/t/t1303-wacky-config.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +test_description='Test wacky input to git config' +. ./test-lib.sh + +setup() { + (printf "[section]\n" && + printf " key = foo") >.git/config +} + +check() { + echo "$2" >expected + git config --get "$1" >actual + git diff actual expected +} + +test_expect_success 'modify same key' ' + setup && + git config section.key bar && + check section.key bar +' + +test_expect_success 'add key in same section' ' + setup && + git config section.other bar && + check section.key foo && + check section.other bar +' + +test_expect_success 'add key in different section' ' + setup && + git config section2.key bar && + check section.key foo && + check section2.key bar +' + +test_done -- cgit v1.2.3 From e5c349ba112fc53832c757cef122297718d3a175 Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Sun, 4 May 2008 01:37:52 -0400 Subject: config.c: Escape backslashes in section names properly If an element of the configuration key name other than the first or last contains a backslash, it is not escaped on output, but is treated as an escape sequence on input. Thus, the backslash is lost when re-loading the configuration. This patch corrects this by having backslashes escaped properly, and introduces a new test for this bug. Signed-off-by: Bryan Donlan Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 99985dcd79..f366b53fb6 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -34,4 +34,10 @@ test_expect_success 'add key in different section' ' check section2.key bar ' +SECTION="test.q\"s\\sq'sp e.key" +test_expect_success 'make sure git-config escapes section names properly' ' + git config "$SECTION" bar && + check "$SECTION" bar +' + test_done -- cgit v1.2.3 From 3af828634fa5bdbca1b2061a81df8b3fa73b0d34 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 23 May 2008 22:28:56 -0700 Subject: tests: do not use implicit "git diff --no-index" As a general principle, we should not use "git diff" to validate the results of what git command that is being tested has done. We would not know if we are testing the command in question, or locating a bug in the cute hack of "git diff --no-index". Rather use test_cmp for that purpose. Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index f366b53fb6..f98f4c5179 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -11,7 +11,7 @@ setup() { check() { echo "$2" >expected git config --get "$1" >actual - git diff actual expected + test_cmp actual expected } test_expect_success 'modify same key' ' -- cgit v1.2.3 From 0cb0e143ffa7d66b7feea0a967b3ac9ae6cd62b0 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Wed, 3 Sep 2008 17:59:27 +0900 Subject: tests: use "git xyzzy" form (t0000 - t3599) Converts tests between t0050-t3903. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index f98f4c5179..1983076c75 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -35,7 +35,7 @@ test_expect_success 'add key in different section' ' ' SECTION="test.q\"s\\sq'sp e.key" -test_expect_success 'make sure git-config escapes section names properly' ' +test_expect_success 'make sure git config escapes section names properly' ' git config "$SECTION" bar && check "$SECTION" bar ' -- cgit v1.2.3 From e0b3cc0dffbc965ffa33155cbdcf8d44716c134c Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Fri, 17 Apr 2009 14:05:11 +0200 Subject: Fix buffer overflow in config parser When interpreting a config value, the config parser reads in 1+ space character(s) and puts -one- space character in the buffer as soon as the first non-space character is encountered (if not inside quotes). Unfortunately the buffer size check lacks the extra space character which gets inserted at the next non-space character, resulting in a crash with a specially crafted config entry. The unit test now uses Java to compile a platform independent .NET framework to output the test string in C# :o) Read: Thanks to Johannes Sixt for the correct printf call which replaces the perl invocation. Signed-off-by: Thomas Jarosch Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 1983076c75..080117c6bc 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -10,7 +10,7 @@ setup() { check() { echo "$2" >expected - git config --get "$1" >actual + git config --get "$1" >actual 2>&1 test_cmp actual expected } @@ -40,4 +40,11 @@ test_expect_success 'make sure git config escapes section names properly' ' check "$SECTION" bar ' +LONG_VALUE=$(printf "x%01021dx a" 7) +test_expect_success 'do not crash on special long config line' ' + setup && + git config section.key "$LONG_VALUE" && + check section.key "fatal: bad config file line 2 in .git/config" +' + test_done -- cgit v1.2.3 From e96c19c50fb0807570b85cb5b8aae6dfcfa9b9ec Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Sun, 10 Apr 2011 22:54:18 +0200 Subject: config: support values longer than 1023 bytes parse_value in config.c has a static buffer of 1024 bytes that it parse the value into. This can sometimes be a problem when a config file contains very long values. It's particularly amusing that git-config already is able to write such files, so it should probably be able to read them as well. Fix this by using a strbuf instead of a fixed-size buffer. Signed-off-by: Erik Faye-Lund Acked-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 080117c6bc..46103a1591 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -44,7 +44,7 @@ LONG_VALUE=$(printf "x%01021dx a" 7) test_expect_success 'do not crash on special long config line' ' setup && git config section.key "$LONG_VALUE" && - check section.key "fatal: bad config file line 2 in .git/config" + check section.key "$LONG_VALUE" ' test_done -- cgit v1.2.3