summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-05-14 13:30:29 -0400
committerEdward Thomson <ethomson@microsoft.com>2015-05-28 09:43:57 -0400
commitd67f270e58942fed5871eca6802d3fa4f290e4f1 (patch)
tree12439058aa4abd0c0de53990ac6a543f09cdba1f
parent3ab5a65967b2007e200be4925781583880e5b938 (diff)
downloadlibgit2-d67f270e58942fed5871eca6802d3fa4f290e4f1.tar.gz
index: validate mode of new conflicts
-rw-r--r--src/index.c9
-rw-r--r--tests/index/conflicts.c9
-rw-r--r--tests/status/worktree.c6
3 files changed, 23 insertions, 1 deletions
diff --git a/src/index.c b/src/index.c
index b39c0893d..e37cb1f4d 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1317,6 +1317,15 @@ int git_index_conflict_add(git_index *index,
(ret = index_entry_dup(&entries[2], INDEX_OWNER(index), their_entry)) < 0)
goto on_error;
+ /* Validate entries */
+ for (i = 0; i < 3; i++) {
+ if (entries[i] && !valid_filemode(entries[i]->mode)) {
+ giterr_set(GITERR_INDEX, "invalid filemode for stage %d entry",
+ i);
+ return -1;
+ }
+ }
+
/* Remove existing index entries for each path */
for (i = 0; i < 3; i++) {
if (entries[i] == NULL)
diff --git a/tests/index/conflicts.c b/tests/index/conflicts.c
index aed5dd1a9..3b38723bd 100644
--- a/tests/index/conflicts.c
+++ b/tests/index/conflicts.c
@@ -47,14 +47,17 @@ void test_index_conflicts__add(void)
memset(&their_entry, 0x0, sizeof(git_index_entry));
ancestor_entry.path = "test-one.txt";
+ ancestor_entry.mode = 0100644;
ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
our_entry.path = "test-one.txt";
+ our_entry.mode = 0100644;
ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
their_entry.path = "test-one.txt";
+ their_entry.mode = 0100644;
ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
@@ -75,14 +78,17 @@ void test_index_conflicts__add_fixes_incorrect_stage(void)
memset(&their_entry, 0x0, sizeof(git_index_entry));
ancestor_entry.path = "test-one.txt";
+ ancestor_entry.mode = 0100644;
ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
our_entry.path = "test-one.txt";
+ our_entry.mode = 0100644;
ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
their_entry.path = "test-one.txt";
+ their_entry.mode = 0100644;
ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
@@ -109,8 +115,8 @@ void test_index_conflicts__add_removes_stage_zero(void)
memset(&our_entry, 0x0, sizeof(git_index_entry));
memset(&their_entry, 0x0, sizeof(git_index_entry));
- staged.mode = 0100644;
staged.path = "test-one.txt";
+ staged.mode = 0100644;
git_oid_fromstr(&staged.id, TEST_STAGED_OID);
cl_git_pass(git_index_add(repo_index, &staged));
cl_assert(git_index_entrycount(repo_index) == 9);
@@ -322,6 +328,7 @@ void test_index_conflicts__partial(void)
memset(&their_entry, 0x0, sizeof(git_index_entry));
ancestor_entry.path = "test-one.txt";
+ ancestor_entry.mode = 0100644;
ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index a8d71477e..de21a1c31 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -461,14 +461,17 @@ void test_status_worktree__conflict_with_diff3(void)
memset(&their_entry, 0x0, sizeof(git_index_entry));
ancestor_entry.path = "modified_file";
+ ancestor_entry.mode = 0100644;
git_oid_fromstr(&ancestor_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
our_entry.path = "modified_file";
+ our_entry.mode = 0100644;
git_oid_fromstr(&our_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
their_entry.path = "modified_file";
+ their_entry.mode = 0100644;
git_oid_fromstr(&their_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
@@ -614,14 +617,17 @@ void test_status_worktree__conflicted_item(void)
memset(&our_entry, 0x0, sizeof(git_index_entry));
memset(&their_entry, 0x0, sizeof(git_index_entry));
+ ancestor_entry.mode = 0100644;
ancestor_entry.path = "modified_file";
git_oid_fromstr(&ancestor_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
+ our_entry.mode = 0100644;
our_entry.path = "modified_file";
git_oid_fromstr(&our_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
+ their_entry.mode = 0100644;
their_entry.path = "modified_file";
git_oid_fromstr(&their_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");