Commit 8dc91e31 by Vicent Martí

Merge pull request #323 from nulltoken/ntk/fix/treebuilder-insert

tree: fix insertion of entries with invalid filenames
parents e6629d83 f4ad64c1
......@@ -379,10 +379,12 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
assert(bld && id && filename);
if (!valid_attributes(attributes))
return git__throw(GIT_ERROR, "Failed to insert entry. Invalid atrributes");
return git__throw(GIT_ERROR, "Failed to insert entry. Invalid attributes");
if (build_ksearch(&ksearch, filename) == GIT_SUCCESS &&
(pos = git_vector_bsearch2(&bld->entries, entry_search_cmp, &ksearch)) != GIT_ENOTFOUND) {
if (build_ksearch(&ksearch, filename) < GIT_SUCCESS)
return git__throw(GIT_ERROR, "Failed to insert entry. Invalid filename '%s'", filename);
if ((pos = git_vector_bsearch2(&bld->entries, entry_search_cmp, &ksearch)) != GIT_ENOTFOUND) {
entry = git_vector_get(&bld->entries, pos);
if (entry->removed) {
entry->removed = 0;
......
......@@ -150,6 +150,11 @@ BEGIN_TEST(write2, "write a tree from a memory")
//create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER.
must_pass(git_tree_lookup(&tree, repo, &id));
must_pass(git_treebuilder_create(&builder, tree));
must_fail(git_treebuilder_insert(NULL, builder, "", &bid, 0100644));
must_fail(git_treebuilder_insert(NULL, builder, "/", &bid, 0100644));
must_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt", &bid, 0100644));
must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
must_pass(git_treebuilder_write(&rid,repo,builder));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment