Commit 0f674411e9358a9d42ba892e853c6abd2303f296

Vicent Martí 2012-11-09T06:16:44

Merge pull request #1052 from delanne/invalid_read Valgrind reports Invalid Read when the configuration file contains some empty line

diff --git a/src/config_file.c b/src/config_file.c
index 1eae8b9..4ca842b 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -924,7 +924,7 @@ static int strip_comments(char *line, int in_quotes)
 	}
 
 	/* skip any space at the end */
-	if (git__isspace(ptr[-1])) {
+	if (ptr > line && git__isspace(ptr[-1])) {
 		ptr--;
 	}
 	ptr[0] = '\0';
@@ -1398,7 +1398,7 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val
 		value_start = var_end + 1;
 
 	do var_end--;
-	while (git__isspace(*var_end));
+	while (var_end>line && git__isspace(*var_end));
 
 	*var_name = git__strndup(line, var_end - line + 1);
 	GITERR_CHECK_ALLOC(*var_name);
diff --git a/tests-clar/resources/config/config11 b/tests-clar/resources/config/config11
index 880c945..7331862 100644
--- a/tests-clar/resources/config/config11
+++ b/tests-clar/resources/config/config11
@@ -1,3 +1,5 @@
 [remote "fancy"]
     url = git://github.com/libgit2/libgit2
     url = git://git.example.com/libgit2
+
+