summaryrefslogtreecommitdiff
path: root/tests/patch/parse.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-10-19 15:42:54 +0200
committerPatrick Steinhardt <ps@pks.im>2019-10-19 17:02:53 +0200
commit223e7e43efffdcab4da864413e70eff40e8ada46 (patch)
tree75c191885996bd8f4a07dee3409bb920a20d9689 /tests/patch/parse.c
parentb246bed5ab83035d8aef95f1b7ff10dd746db7cb (diff)
downloadlibgit2-223e7e43efffdcab4da864413e70eff40e8ada46.tar.gz
patch_parse: reject patches with multiple old/new paths
It's currently possible to have patches with multiple old path name headers. As we didn't check for this case, this resulted in a memory leak when overwriting the old old path with the new old path because we simply discarded the old pointer. Instead of fixing this by free'ing the old pointer, we should reject such patches altogether. It doesn't make any sense for the "---" or "+++" markers to occur multiple times within a patch n the first place. This also implicitly fixes the memory leak.
Diffstat (limited to 'tests/patch/parse.c')
-rw-r--r--tests/patch/parse.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/patch/parse.c b/tests/patch/parse.c
index b89322ff3..fb185eb2a 100644
--- a/tests/patch/parse.c
+++ b/tests/patch/parse.c
@@ -148,3 +148,9 @@ void test_patch_parse__lifetime_of_patch_does_not_depend_on_buffer(void)
git_patch_free(patch);
}
+
+void test_patch_parse__memory_leak_on_multiple_paths(void)
+{
+ git_patch *patch;
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_MULTIPLE_OLD_PATHS, strlen(PATCH_MULTIPLE_OLD_PATHS), NULL));
+}