Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Vladimirov <nikolay@vladimiroff.com>2013-08-08 22:17:32 +0400
committerNikolai Vladimirov <nikolay@vladimiroff.com>2013-08-08 23:25:25 +0400
commitc57f668268744cbccb13c30095a0c1649fb18a63 (patch)
tree4cbe2a6d43db3577fcc0ea2ef10b8fcb687eb37b /src/config_file.c
parentc5780abb024a3d570bc1e7eb8c892a60b77bad84 (diff)
config: allow empty string as value
`git_config_set_string(config, "config.section", "")` fails when escaping the value. The buffer in `escape_value` is allocated without NULL-termination. And in case of empty string 0 is passed for buffer size in `git_buf_grow`. `git_buf_detach` returns NULL when the allocated size is 0 and that leads to an error return in `GITERR_CHECK_ALLOC` called after `escape_value` The change in `config_file.c` was suggested by Russell Belfer <rb@github.com>
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 2b0732a13..605e2e99c 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1293,6 +1293,9 @@ static char *escape_value(const char *ptr)
assert(ptr);
len = strlen(ptr);
+ if (!len)
+ return git__calloc(1, sizeof(char));
+
git_buf_grow(&buf, len);
while (*ptr != '\0') {