summaryrefslogtreecommitdiff
path: root/tests/patch
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
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')
-rw-r--r--tests/patch/parse.c6
-rw-r--r--tests/patch/patch_common.h7
2 files changed, 13 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));
+}
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index d730d142c..68b183d38 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -905,3 +905,10 @@
"-b\n" \
"+bb\n" \
" c\n"
+
+#define PATCH_MULTIPLE_OLD_PATHS \
+ "diff --git \n" \
+ "--- \n" \
+ "+++ \n" \
+ "index 0000..7DDb\n" \
+ "--- \n"