Commit 19af78bb by Scott J. Goldman

Prevent creating `..`, `.`, and `.git` with tree builder

As per core git.
parent 629c0829
...@@ -26,7 +26,9 @@ static bool valid_filemode(const int filemode) ...@@ -26,7 +26,9 @@ static bool valid_filemode(const int filemode)
static int valid_entry_name(const char *filename) static int valid_entry_name(const char *filename)
{ {
return *filename != '\0' && strchr(filename, '/') == NULL; return *filename != '\0' && strchr(filename, '/') == NULL &&
strcmp(filename, "..") != 0 && strcmp(filename, ".") != 0 &&
strcmp(filename, ".git") != 0;
} }
static int entry_sort_cmp(const void *a, const void *b) static int entry_sort_cmp(const void *a, const void *b)
......
...@@ -39,6 +39,12 @@ void test_object_tree_write__from_memory(void) ...@@ -39,6 +39,12 @@ void test_object_tree_write__from_memory(void)
&bid, GIT_FILEMODE_BLOB)); &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "/", cl_git_fail(git_treebuilder_insert(NULL, builder, "/",
&bid, GIT_FILEMODE_BLOB)); &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "..",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt", cl_git_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt",
&bid, GIT_FILEMODE_BLOB)); &bid, GIT_FILEMODE_BLOB));
......
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